Wednesday, January 9, 2013

JavaScript Determine which key is pressed

Needed to act based on button pressed. So here it is.


function RandomEP(e)
{
var evtobj=window.event? event : e //distinguish between IE's explicit event object (window.event) and Firefox's implicit.
var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode
var actualkey=String.fromCharCode(unicode)
if (actualkey=="d")
{
//your code here
}
}

Then in the body tag you insert onkeypress=”RandomEP()” or whatever your function is called.

Wednesday, January 2, 2013

TSQL Make Directory

Create a directory using xp_cmdshell. Script includes steps to enable xp_cmdshell and then disabling it when finished. Take that out if you want.



--ENABLE xp_cmdshell to execute the mkdir
EXEC sp_configure 'show advanced options', 1
GO RECONFIGURE
GO EXEC sp_configure 'xp_cmdshell', 1
GO
RECONFIGURE
GO
--Make the directory

DECLARE @cmd VARCHAR(100), 
       @directory VARCHAR(100) = 'C:tempjoe ' + @@SERVERNAME 
SET @cmd = ' mkdir ' + @directory
EXEC xp_cmdshell @cmd, no output

--Disable xp_cmdshell
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
EXEC sp_configure 'xp_cmdshell', 0
GO
RECONFIGURE
GO

Monday, December 31, 2012

Torque Stats with a CTE

Using a Common Table Expression in SQL to analyze some Performance stats from the OBD scanner.



;WITH cteRawData AS (
SELECT CAST(TripAvgMPG as float) TripAvgMPG,
runid,
ROW_NUMBER() OVER(PARTITION by runid order by CAST(DeviceTime as datetime)  DESC) as RowNum
from rawdata
)
SELECT c.TripAvgMPG,
c.RowNum,
c.runid,
AVG(CAST(r.SpeedOBD as float)) AvgSpeedOBD,
MAX(CAST(r.SpeedOBD as float)) MAXSpeedOBD,
MAX(CAST(r.DeviceTime as DateTime)) DeviceTime,
AVG(CAST(r.AbsThrottlePositionPCT as float)) AVGAbsThrottlePositionPCT,
AVG(CAST(r.EngineRPM as Float)) AvgEngineRPM,
CONVERT(varchar(10), DATEADD(second,MAX(CAST(TripTimeMoving as float)) - MIN(CAST(TripTimeMoving as float)),0),108) TripTimeMoving,
CONVERT(varchar(10), DATEADD(second,MAX(CAST(TripTimeOverall as float)) - MIN(CAST(TripTimeOverall as float)),0),108) TripTimeOverall,
CONVERT(varchar(10), DATEADD(second,MAX(CAST(TripTimeStationary as float)) - MIN(CAST(TripTimeStationary as float)),0),108) TripTimeStationary
FROM cteRawData c
JOIN rawdata r ON c.runid = r.runid
WHERE c.RowNum = 1
GROUP BY c.TripAvgMPG,c.RowNum,c.runid
order by c.TripAvgMPG

Friday, July 13, 2012

Monday, July 2, 2012

Oracle User expired password

Use this command to extract the password and generate the ALTER user statement needed to un-expire an oracle password:


select 'alter user "'||username||'" identified by values '''||extract(xmltype(dbms_metadata.get_xml('USER',username)),'//USER_T/PASSWORD/text()').getStringVal()||''';'  old_password  from    dba_users where username = 'username';

Thursday, June 28, 2012

Wednesday, June 20, 2012

Converting 3ga to MP3 using VLC

Love the VideoLan media player. Seems like it can play just about any type of media file. Found a new feature that I like today: File Conversion. I was able to take a 3ga file (recording from my Droid) and convert it to a MP3.

  1. Open the file in VLAN

  2. Click on the Media folder and click the Conver/Save option.

  3. Add your 3ga file to the file selection

  4. Click the arrow on the Convert/Save Button and choose Convert

  5. Pick your destination file

  6. In the Profile Drop down box scroll down to the Audio - MP3 profile.

  7. Click Start.

  8. Bam! 

Monday, June 11, 2012

Thursday, May 10, 2012

Pushingbox.com Web Service

Just discovered http://www.pushingbox.com. Man this is a great free service. As a matter of fact, I am not sure how long this service will be free. The website exposes an API that allows you to send emails or push notifications  to cell phones. The API can be called from CURL, php or a python script. I downloaded the CURL exe and tried it out with some simple VBScripts.


I wanted to setup a monitor to watch the indoor temperature on my house and send me an email notification. I will add other monitors using data from my weather station going forward, but just wanted to setup this quick test.


1. Sign up at the PushingBox.com web site. I just used my google sign in. One gripe about the site is that its a little slow


2. Click on My Services and Add a service. You can add email and such. I went ahead and download Notifry from the Google Play Store. Once you install Notifry you have to get it setup and they give you a big long API ID. You have to type that in on the add service page when you add Notifry



Pro Tip: make sure you disable the Autmoatic talk feature on Notifry…otherwise when you send your first test your phone will automatically read the message outloud upon receipt…that was a nice surprise when I first tried it.


3. Click on My Scenarios. Give your Scenario a name. I called my Indoor Temperature Monitor and click Create. Here you will be able to setup your message. I am using a variable in my message which is designated using the $variablename$ syntax. This is because I wanted my message to tell me how hot the house is. 



4. Once you have created a scenario you will be given a device ID. You will need this device id in the CURL call or whatever method you are using to call the API. Capture that DeviceID for later use.



5. Test the API by visiting the device id in a web page: http://api.pushingbox.com/pushingbox?devid=v1234567890&indoortemp=91


Replace the v1234567890 with your DeviceID and the indoortemp with your variable name.


If all works according to plan you should receive a push notification on your mobile device.


If that does not work, make sure you have your device setup correctly. Switch over to email on the services and try to test receiving an email.


6. Now you are ready to script it up. Again I used CURL but you can use PHP or Python or whatever.


Here is my VBScript:


set fso = CreateObject("Scripting.FileSystemObject")
set f = fso.OpenTextFile("temp.txt",1,True)
Set WshShell = CreateObject("WScript.Shell")

while not f.AtEndOfStream
lineread = f.ReadLine
lineArray = Split(lineread,"|",-1)
currtemp = lineArray(1)

if currTemp > 80 then
Set oExec = WshShell.Exec("c:scriptscurl ""http://api.pushingbox.com/pushingbox?devid=v12345678990&indoortemp=" & currTemp & """")

Do While oExec.Status = 0
WScript.Sleep 100
Loop
end if
wend

I just hardcoded a test file in this case. I will play with my weather station output this evening. This will just check to see if the temperature in this text file is over 80 degrees. Here is a sample of the text file:


IndoorTemp|89


I will have to modify that to parse out the temperature text file…but you get the gist. So now if my house gets over 80 degrees I will get a push notification. Pretty cool.

Wednesday, May 2, 2012

Mount ISO AIX 6.1

To mount ISO


loopmount -i /iso/dvd.iso -l loop0 -o "-V cdrfs -o ro" -m /mnt/dvd

To umount ISO


loopumount -l loop0 -m /mnt/dvd

If you get a message stating that Specified Loopback device is not found in ODM then you can run this command to make a loopback device.


mkdev -c loopback -s node -t loopback