OWA Dump
I always try to find a way to make my work more convenient. Recently my company decided to drop all employee blackberries and instead to provide us with allowance for our own phones. Everything would be great if not this one little problem with that. I get a lot of alerts and status updates on my work email and by a lot i mean A LOT. I wanted to have an ability to quickly check my work email when I wanted, with minimal impact to my phone configuration and battery life. The trick is that the only way to do that is either through Exchange Server or through Outlook Web Access (OWA). I started analyzing my options and finally settled on something that could dump my email list to a file in the cloud that I can easily view from anywhere, when I want, and without inconvenient login system. Then I realized that dumping a text file to my dropbox would be the best option.
At this point I needed something that could read emails by connecting to Exchange Server or by parsing emails from OWA. Exchange Server route seemed too complicated for my needs so I started working on OWA parsing script. I decided to use VBScript due to easy IE automation. At the end I had a script dumping all my emails to a text file. I set that text file to sync with my dropbox and scheduled the script to run on a short interval. Problem solved.
Check out the script here: http://mattstypa.com/owa-dump/
Converting CSS colors to grayscale
Last week I was working on integrating punBB into my website and I ran into a small challenge. I needed to make punBB match my blog's color scheme. By default punBB looks like this:
I started editing the CSS file and quickly realized that it is going to take much more time and effort that I was willing to invest at that time. I started analyzing alternative solutions and quickly figured out that converting the default color scheme to grayscale would do the trick. I started looking online for a tool that could do such a thing. I didn't find anything but it didn't seem too hard to write a script that would change all the colors in a css file. Having absolutely no idea how to convert an RGB code from color to grayscale I setup my first experiment.
If RGB code describes intensity of red, green, and blue respectively, if I total the intensity values and then spread them evenly between red, green, and blue I should get gray of the same intensity as the base color. With that assumption in mind, I wrote the following VBScript code. I realize that it's dirty and could be written much better but I had 5 minutes to write it and it worked so don't wine.
'Setting up System File Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Opening input css file. 1 = reading
Set inFile = objFSO.OpenTextFile("in.css", 1)
'Opening output css file. 2 = writing
Set outFile = objFSO.OpenTextFile("out.css", 2)
'Main loop
Do Until inFile.AtEndOfStream
'Read a line from input file
line = inFile.ReadLine
'Find position of first "#"
pos = InStr(line,"#")
'If "#" was found pos will be larger then 0. The reason this is a while loop is that "#" could occur more then once per line
while pos > 0
'Checking if the "#" found could be a 3 digit color code
if mid(line,pos+4,1)=" " or mid(line,pos+4,1)=";" then
'Converting rgb values to decimal from hex
r = CInt("&H" & mid(line,pos+1,1))
b = CInt("&H" & mid(line,pos+2,1))
g = CInt("&H" & mid(line,pos+3,1))
'This is where the conversion to grayscale happens
t = hex((r+b+g)/3)
'Rebuilding the line with the new value
line = mid(line,1,pos) & t & t & t & mid(line,pos+4)
'Checking if the "#" found could be a 6 digit color code
elseif mid(line,pos+7,1)=" " or mid(line,pos+7,1)=";" then
'Converting rgb values to decimal from hex
r = CInt("&H" & mid(line,pos+1,2))
b = CInt("&H" & mid(line,pos+3,2))
g = CInt("&H" & mid(line,pos+5,2))
'This is where the conversion to grayscale happens
t = hex((r+b+g)/3)
'Making sure that t is two digits long and if not add "0" in front
if t < 2 then
t = "0" & t
end if
'Rebuilding the line with the new value
line = mid(line,1,pos) & t & t & t & mid(line,pos+7)
end if
'Checking for another "#" on this line
pos = InStr(pos+1,line,"#")
wend
'Write to the output file
outFile.WriteLine(line)
Loop
'Closing files
inFile.Close
outFile.Close
'Done
msgbox("Done")
Amazingly it worked like a charm so enjoy it.
Batch Image Resizer 1.1 released
Batch Image Resizer 1.1 has been released.
This program allows you to easily resize large amount of images. While extremely powerful it is also lightning fast and lightweight.
Head over to Batch Image Resizer page for more information.