Thursday, December 29, 2005

Hospitals Are So 1500s

I had a fun Christmas! Oh boy I did. My wife was hospitalized this last weekend during Christmas and it was a blast. I have never seen a more convoluted, slow, shift the responsibility on the next shift bunch of crap in my life.

Health care is the only business I know where customer service is uneccesary. Why? The answer is simple. No matter how bad their service, a hospital is not going to lose any business. In fact as long as they do not kill you they are almost guaranteed you will come back. This is especially true in areas with very few hospitals.

If you wonder why your medical bills are so high look no further than your local hospital's emergency rooms. You wait 3 hours to get a room (if you're lucky). Then 2 hours later a man comes in for some blood work. If you are unlucky enough to go towards the end of a shift the current shift is looking for a way to shift your case to the next shift. In other words be prepared to have to wait until 4 in the morning to get admitted to the actual hospital from the emergency room if you come in past 8 in the evening be prepared to wait as people shuffle you from person to person like some strange inefficient ballet.

Then, when you do get your room be prepared to be interrupted every hour on the hour as your vitals get checked, blood drawn, etc. Then be prepared to wait for the next afternoon for a Doctor to actually dain to come and release you from the hospital. All in all hospitals are prime example of human stupidity, laziness and inefficiency. Then we wonder why a basic hospital visit costs $1000 a day. I don't have to wonder anymore.

If I ran my businesses like hospitals are run I would not have a business.

Tuesday, December 20, 2005

Merry Xmas

Merry Chrismas to all. I will be taking a break from writing from now until next Wednesday in observance and celebration of the season. I hope you all have a wonder Christamas holiday.

Monday, December 19, 2005

Inconvenient Temp Files

Recently I had a temp directory that shut down a server by filling up the C drive. The culprit was a nightly job that unzipped temp files into the temp directory (Go Figure ;-)). The solution was simple. Create a Perl job to kill those files nightly before that other job runs. The code follows:

# This program get's rid of all the files matching regex $regex (ckz_* in our case)
# temp files for user ARGV[0]

use File::Path;
my $user = $ARGV[0];
my $regex = $ARGV[1];
my $temp_dir = "C:\\Documents and Settings\\$user\\Local Settings\\Temp";
if (-d $temp_dir) {

      opendir(DE,$temp_dir);
my @all_files = readdir(DE);
foreach $file (@all_files) {
# Make sure file is not a directory
$entry = "$temp_dir\\$file";
if (-d $entry) {
if ($entry =~m/$regex/i) {
print "DELETING ENTRY: $entry\n";
rmtree($entry);
}
}
}
closedir(DE);
}

else {

print "Directory $temp_dir Does Not Exist!";
}

This code removes any temp files matching $regex in the user $user temp files. These two variables are passed in on the command line ($ARGV[0],$ARGV[1]).

Funny Clause

http://members.cox.net.nyud.net:8090/jmccorm/santa.html

Enough said.

Friday, December 16, 2005

The Travails Of Using SMS Messaging To Communicate Server Downs

Recently, my company email servers have been flaky. It has been decided that we needed a way to communicate server downs to the IT staff so we can take corrective actions. The easiest way I could come up with was SMS messaging to our company cell phones. The only problem is that my company is cheap and SMS services that you can call programmatically cost money.

Perl came to the rescue yet again. I remembered that the T-Mobile website (our cell service provider) had a web page you could use to communicate with T-Mobile cellphones. You only needed an existing account setup on their site (with your mobile number and a password).

Armed with this knowledge I started using Samie and Win32::GuiTest to automate Internet Explorer to do the whole process automagically. Samie is a great package but it does have some issues. Some of the procedure calls do not work as expected. I've posted a modified version that works with my code at:

http://www.streamload.com/lamberms/Sam.pm

Anyway, here is the code solution to do SMS messaging. It comes in two parts, tmobile_sms.pl and kill_ie.pl. You call tmobile_sms.pl with five arguments, your T-Mobile cell phone number, account password, T-Mobile phone number to sms, from information and the message. It then automates IE to go to the T-Mobile web page, log in and send the message. When it is done doing this kill_ie.pl kills the popup the T-Mobile web site pops up (Samie does not do this well) and closes IE. Here is the tmobile_sms.pl code:

use Win32::OLE;
$Win32::OLE::Warn = 3;
use Win32::SAM;
$| = 1;
my $URL = "https://my.t-mobile.com/Communication/";
my $IEDocument;
my $seconds;
my $account_mobile_num = @ARGV[0];
my $account_mobile_pass = @ARGV[1];
my $mobilenum_to_page = @ARGV[2];
my $from_text = @ARGV[3];
my $msg_text = @ARGV[4];

if (@ARGV[0] eq "" || @ARGV[1] eq "" || @ARGV[2] eq "" || @ARGV[3] eq "" || @ARGV[4] eq "") {

       print "Invalid Command Used.  Command Should Be Formatted Like:\n";
print "tmobile_sms.exe your_cell_phone_num your_cell_phone_pass cell_phone_to_sms from_text msg_text\n";
exit;

}

StartIE();
$seconds = Navigate($URL);
print "First Page took $seconds seconds to load\n";
SetEditBox("txtMSISDN",$account_mobile_num);
SetEditBox("txtPassword",$account_mobile_pass);
ClickImage("https://my.t-mobile.com/images/mytmobile/ph/buttons/leftp.gif",0,1);
print "Second Page Loaded In $seconds.\n";
while (not VerifyTextPresent("SELECT A PHONE")) {

       print "Select A Phone Text Is Not Present\n";
sleep(1);

}
$seconds = Navigate($URL,0,1);
print "Third Page Took $seconds seconds\n";
while (not VerifyTextPresent("Characters left")) {

       print "Characters left Text Is Not Present\n";
sleep(1);

}
SetEditBox("txtNum","$mobilenum_to_page");
SetEditBox("txtFrom","$from_text");
SetEditBox("txtMessage","$msg_text");
$seconds = ClickImage("https://my.t-mobile.com/images/mytmobile/ph/buttons/left.gif",0,1);
if (-e ".\\kill_ie.exe") {
exec(".\\kill_ie.exe");
}

if (-e ".\\kill_ie.pl") {
exec(".\\kill_ie.pl");
}
exit;

And here is the kill_ie.pl code:

use Win32::GuiTest;

$| = 1;
my @windows = ();
my $time_counter = 0;
while ($#windows == -1 && $time_counter < 121) {

     @windows = Win32::GuiTest::FindWindowLike( undef, "^Microsoft Internet Explorer", "","",5 );
$time_counter++;
print "Looking For Popup Window\n";
Win32::Sleep(1000);

}

if ($time_counter == 120) {

     print "FAILURE Finding Microsoft Internet Explorer Window!!!!\n";
exit;

}

else {

if ( !bring_window_to_front( $windows[0] ) ) {

print "* Could not bring to front $window[0]\n";
}

     my @enterbutton = Win32::GuiTest::FindWindowLike( undef, "OK", "Button" );
if ($#enterbutton > -1) {
#Click OK Button
Win32::GuiTest::SendKeys("~",1);
Win32::GuiTest::SendKeys("%({F4})");
print "Clicking OK Button\n";
exit;
}
else {
print "Could Not Click Enter Button\n";
exit;
}

}

exit;

sub bring_window_to_front {


my $window = shift;
my $success = 1;
if ( Win32::GuiTest::SetActiveWindow($window) ) {
print "* Successfully set the window id: $window active\n";
}
else {
print "* Could not set the window id: $window active\n";
$success = 0;
}
if ( Win32::GuiTest::SetForegroundWindow($window) ) {
print "* Window id: $window brought to foreground\n";
}
else {
print "* Window id: $window could not be brought to foreground\n";
$success = 0;
}
return $success;

}

Thursday, December 15, 2005

Mono Is A Game


After my last blog entry on Mono the development environment I thought it would be appropriate to talk about my new game obsession, Mono. In this game you go around shooting simple spheres and collecting powerups that increase the power level of your shots. All of this is happening to a simple techno score and it just ROCKS! It is like asteroids with a twist and I cannot get enough of it. I think you might like it as well.

Wednesday, December 14, 2005

Orange Is Not Just A Fruit Anymore


For a long time now I have been fascinated by the use people make of such open source tools as Blender, Povray, Audacity, etc. Put together, these excellent 3d rendering and sound packages make it possible for the end user to produce Pixar quality short films. As proof, I offer up Project Orange. This is a project to use Blender and other open source tools to produce a short film. The blogs on this site give quite a bit of insight as to what it takes to produce creative works with free tools. It makes for interesting reading.

Tuesday, December 13, 2005

Mono Is Cool In Concept

I've been working a bit with Gentoo Linux lately and I was curious about cross platform development between WinBlows and Linux (Yeah, I know, gross!). The one project I came up with that seemed plausible was Mono. Mono is a cross-platform development environment that uses basically replaces .Net. It has the C# language (the flagship of .NET development) and it seems relatively complete. The only problem I see so far is a problem that affects many open and closed source projects ... the documentation sucks. I am looking to compile a set of C# code into a dll and it is next to impossible to figure out how. I'm probably missing something. I'll report what I find out in the next few days on the blog.

Monday, December 12, 2005

I've Been Dug

Looks like I have been dug 10 times at digg.com. Check it out at:

http://digg.com/programming/Resize_And_Markup_PDFs_For_Free

Welcome diggers ;-)!

Friday, December 09, 2005

Resize And Markup A PDF For Free (Well If You Have The .Net Dev Environment Anyway)

Well, yesterday I promised you code to resize or markup pdf documents. I've been frustrated for years because every library I ever used made the pdf look horrible when I did a resize. Then ITextSharp entered my life and everything changed. After a bit of work I was able to come up with the code that allows me to resize a pdf to A,B,C,D,E,A3 or A4. I can also markup the pdf. This code will create a command line program for you that will do the same.

To get this working:

  1. Create a new Console Application VB .NET project
  2. Set a reference to the ITextSharp dll (found from the ITextSharp link above)
  3. Set the startup object as the Main subroutine in the code
  4. Build the project
After building the project you will get a command line program. The arguments to this program will be:

  1. Source PDF file
  2. Destination PDF File
  3. Operation - Resize or Markup
  4. The size for the destination PDF (A,B,C,D,E,A3 or A4) or the markup text
Since the commercial alternatives to this free software cost "real" money, I would not mind a small donation (if you feel really generous). To do this use the following link (defaults to $10):



The code can be downloaded at:

http://www.streamload.com/lamberms/PDFCommandLineCode.zip

Happy Coding!

Thursday, December 08, 2005

Stay Tuned

I'm working on some code feverishly for resizing and "watermarking" PDF files. This has been the bane of my existence at work. Getting it correct programmatically is a pain. This has made it necessary for me to purchase utilities for doing this in the past. I wish to save you this expense if I can. So anyway, stay tuned in the next day or two for some VB .NET code for resizing PDFs followed by code for marking up PDFs.

Wednesday, December 07, 2005

Playing With PDFs Programmatically

Let's face it, PDFs have become the defacto standard for sharing documents with your employees and customers. The problem comes in when you want to automatically generate things like invoices, quotations, etc. programmatically. I am constantly playing with PDFs at my day job as all of our drawings are converted to that format. It is not unusual for me to want to do things like watermark and resize these documents. When I want to do these kinds of things I turn to a few different libraries depending on what environment I am currently in. Here are a list of the libraries I am currently using:

1. Perl - PDF::API2
2. Java - Itext
3. .NET - ITextSharp

With these libraries on your side PDF manipulation ceases to be a chore and becomes fun (OK, well tolerable then).

Monday, December 05, 2005

Christmas Times A Coming

Oh, Christmas, where have you gone? Do you remember when Christmas did not mean doing a mad dash for cash until December 25th? Do you remember when it really was the thought that counted? Do you remember when you did not have to spend $1200 at Christmas just to "satisfy" everyone? Do you remember when just being together was Christmas enough.

I wish instead of remembering this I was experiencing it now.

Friday, December 02, 2005

My Head's In The Clouds


I am not usually a fan of games that don't involve First Person Shooter characteristics. That may explain why I came to Cloud with low expectations. I thought I would find boredom, instead I found a non-linear, entertaining and engaging game. Give it a check out.

Thursday, December 01, 2005

Just Curious

Hey there everyone. I was just wondering if anyone was reading my ramblings. If you are could you post a comment and let me know you are out there ;-)?

Spyhunter Rides Again


Remember the SpyHunter arcade game? I do. I remember how it bankrupted my tight budget as I tried to stay one step ahead of the enemy vehicles and ended up feeding quarter after quarter into the darn machine.

Thankfully, with the Internet, I have an alternative to bankruptcy and it's called Highway Pursuit. This freeware game is basically SpyHunter for a Windows machines and has the advantages of being free and a lot prettier than the original. Check it out for some good ol' fashioned fun.