Archive for the ‘Programming’ Category

Weblog Pictures and Gallery

Tuesday, January 13th, 2004

I’ve been meaning to add some pictures to my weblog for quite a while so tonight I decided to spend a little time and develop something. I’ve been using Gallery for my photo gallery and I wanted something that would integrate somewhat with it. Here’s what I did:

  1. I created a photo album in gallery called “Random” (I set the thumbnail size to be 200 for the album).
  2. I uploaded a bunch of photos that I wanted to appear on the weblog to the “Random” album.
  3. I wrote a nice little php script that selects a thumbnail of a picture at random. The picture also links to the larger picture. That’s about all there is to it. Here’s the code:

    <?php

    $d = dir(”../albums/random/”);

    while (false !== ($entry = $d->read())) {

         if (false !== ($pos = strpos($entry, “.thumb.jpg”))) {

             $picArray[] = $entry;

             $linkArray[] = substr($entry, 0, $pos);

         }

    }

    srand ((float) microtime() * 10000000);

    $pos = array_rand ($picArray,1);

    echo “<a

    href=”/gallery/view_photo.php?set_albumName=random&id=”.$linkArray[$pos].”" target=”_blank”>”;

    echo “<img src=”/”.$d->path.$picArray[$pos].”" border=”0″/></a>”;

    $d->close();

    ?>

  4. I thought it might be nice to add a border to the pictures, to accent them a little. To do that I added a few lines to the style-sheet template in MovableType:

    .randomImages {

         font-family:verdana, arial, sans-serif;

         color:#333;

         font-size:x-small;

         font-weight:normal;

         background:#FFF;

         line-height:140%;

         padding:2px;

    }



    .randomImages img {

         border: 2px solid #a98c4b;

    }

  5. The last step was wrapping my php script in a div tag:

    <div class=”randomImages” align=”center”>

        …PHP CODE HERE…

    </div>

That’s all there was to it. I’m pretty pleased with the results. All I have to do to add more pictures is upload them to the “Random” album using gallery. One of these days maybe I’ll try and integrate it more tightly with Gallery and pull the picture caption also.

Coldfusion MX 6.1 Upgrade Continued

Sunday, December 28th, 2003

I’ve been procrastinating finishing my upgrade entry because one of the problems I ran into was a little troublesome to fix. If I was smart I would have made the upgrade entry immediatlely after I fixed it, while the problem and solution was fresh in my mind. Now that a few weeks have passed I can’t recall all the details so you’re going to get a watered down explanation of what I did.

Basically, after the upgrade, all credit card processing on our site went down. Fortunately it’s not something we use a lot on our site but it was still important to have fixed. I isolated the problem to the COM object we were calling to do the processing. Basically we just initialize the object with the server name, port number, credit card information, etc and the object connects to the credit card server and takes care of the rest. After the upgrade, the code that set the port number was throwing a mysterious error. Something like “VT_22 unsupported” or something along those lines. I discovered that MX seems to have a problem with passing integer arguments to COM objects. Passing something like: MyObject.ServerName(”someserver.somedomain.com”); would work fine. However, MyObject.ServerPort(5555); would throw the error. I checked around the Macromedia forums and only found a few vague references to the problem but no solutions. Finally I came across a page that described a way to create a Java stub for a COM object. Basically creating a java class that will interface with the COM object. So instead of calling the COM object directly within the code you call the Java object. Information on how do this can be found here.

The original code looked something like this:

<cfobject type=”com” action=”create” class=”MyComObject.Foo” name=”MyComObject”>

using the java stub it looked something like this:

<cfobject type=”java” action=”create” class=”MyComObject.Foo” name=”MyComObject”>

Fortunately the credit card processing was contained in a custom tag so I only had to modify the one line in the custom tag, after I created the java stub of course, to have everything working. Incidentally the next day I came across a “” that from reading the description appears to solve the problem. However, the hotfix was released the day before I created my java stub and I didn’t find it until after the problem was resolved. I haven’t applied the hotfix or tested it to see if the COM objects work with integers. However, if you’re having this problem I would definitely try the hotfix first before creating the stub since you shouldn’t have to modify your code and it’s probably much simpler than creating the stub.

The last nagging problem we’ve had with the upgrade is mysterious “null null” errors. Quite a descriptive error isn’t it? We’ve isolated a few of the causes to improperly used date functions (such as creating a date with 0 for the month, apparently this worked in 5.0 but now causes a null null error in MX). However, we’re getting the error seemingly at random in a few pages that don’t use any date functions. I suspect it has something to do with cookies since clearing the cookies on the client has solved SOME of the errors. I still haven’t been able to erradicate the error completely. It’s difficult since the error isn’t descriptive at all, null null gives me no clues about what’s causing the problems. The line number the error is reported on is also wrong (a few null null errors have been reported on blank lines or lines that are only comments). Debugging the error is truly like searching for a needle in a hay stack.

Even with the problems I had with the upgrade I’m still impressed with a few of the additions to MX. I wrote my first application the other day using a a cfc. Being able to remove the business logic from the display code made for a much cleaner implementation which I expect will utlimately make it easier to maintain and scale. Now if I can get the rest of my team to use it correctly we’ll be in good shape.

Mozilla vs IE and Safari (tip: Using System Default Mail Program with Mozilla)

Tuesday, December 2nd, 2003

When I got my powerbook I switched from using Internet Explorer to Safari solely because Safari had tabs and IE didn’t. I was happy with Safari but then heard rumors it suffers from a memory leak. I decided to continue using Safari, once again, solely because of the tabs. At about this time I got my new x86 laptop at work with Windows XP which means I was back to IE (at work anyway). Honestly it drove me nuts opening a new window for every page I wanted to view. Not too mention when you open 3 or 4 windows of the same program in XP they scrunch together as one on the task bar, making it cumbersome to navigate between them.

A guy I work with recommended Mozilla and when I realized it had tabs I was sold. I installed it on both my Powerbook and Dell D600 and have never gone back or felt the need to try anything else. The only thing that’s been annoying me is when I click on mailto links, it tries to open the Mozilla mail program (composer). I’ve searched the “Preferences” window repeatedly for a setting to “Use the system default mail program”. Tonight I finally decided to search Mozilla’s site, figuring at least a few other people have found this annoying. Sure enough I found the solution. Now my web browsing world is perfect.

Mozilla also comes with a built-in Javascript Debugger, very nice for a web developer. Also, since I’ve started doing full time web development I’ve gained a greater loathing for IE. The behaviour amazes and disgust me at times.

For example, today I was tweaking a page for a new site I was working on. Basically I copied a template from another of our sites and proceeded to change the graphics, menus, etc. On the top of the page there was a logo graphic 90 pixels tall, to the right was another graphic that was 70 pixels tall and another below it 20 pixels tall (all with borders=”0″). It looked fine in Mozilla, but when I checked it in IE I was stunned when I loaded the page and noticed the logo graphic had a gap on the top and bottom. I checked the other two graphics closely and they appeared to stretch from top to bottom with no gaps. I double and triple checked the graphic dimensions and img tags with no luck. I loaded the site I took the code from and everything appeared fine. I switched the graphics with those from the site that was working and the gap was still there. The code was almost exactly the same except for one thing. The site that was working used javascript for the top right image (70 pixel one) to automatically select a random picture when the page was loaded. The code looked something like this:

<script language=”JavaScript” type=”text/javascript”>

var random = Math.round(Math.random()*(4-1))+1;
document.write(’<img src=”/images/top_images/image’ + random + ‘.jpg” width=”469″ height=”70″ border=”0″/>’);

</script>

However on the new site I only had a single graphic so there was no need to use the javascript I just replaced it with:

<img src=”/images/top_image.jpg” width=”469″ height=”70″ border=”0″/>

No problem right? Not with IE. Since that was the only code difference I could see, I replaced the img tag with the following javascript:

<script language=”JavaScript” type=”text/javascript”>

document.write(’<img src=”/images/top_image.jpg” width=”469″ height=”70″ border=”0″/>’);

</script>

Reloaded the page, and suddenly the gap disappears, all is well with IE again. Strange and utterly annoying. How much time did I waste trying to figure out what was going on? TOO MUCH!!

MAX Conference Summary

Sunday, November 23rd, 2003

I attended the Macromedia MAX conference this past week in Salt Lake City. I intended to write a few entries about the conference while I was there but never got around to it. Overall it was a good conference. I decided we really need to migrate our system to ColdFusion MX 6.1. Now that I think about it all the sessions I attended dealt with things that can only be done with MX.

Most of the sessions I went to dealt with CFC’s (coldfusion components) which were added to MX. Basically it enables object oriented programming in ColdFusion, although it’s pseudo OOP. For web purposes I think it’ll work great. ColdFusion itself is actually a procedural language. Now with the addition of CFC’s you get the benefits of OOP and procedural all in one. There are a few limitations such as single inheritance (a CFC can only extend one other CFC), although you can chain the inheritance (ie. a.cfc extends b.cfc which extends c.cfc etc…) but like I said for the web I think you can get by in most cases.

A few of the benefits I see to using CFC’s:

  • Business logic can be easily seperated from from presentation logic. Currently (in 5.0) the .cfm files can become fairly large with queries, custom functions and other code embedded throughout the presentation logic. With CFC’s you can keep all your queries, custom functions, etc seperate from the cfm files. Very nice.
  • EASILY deploy web services. Using CFC’s it’s possible to deploy a web service in less than 5 minutes (we actually did it in a hands on lab). Not only is it easy to create a web service it’s possible to lock the security down to individual functions within the cfc file.
  • .cfc files are self documenting. By pointing a web browser to the .cfc file on the server an html file is returned with a complete description of the file and it’s available functions.
  • Promote code reuse
  • Makes it much easier to model real world problems (create a cfc for each entity)

I could go on and on, but I won’t. I took a few pictures during the conference. I’ll post a link to’em when I get them uploaded. Unfortunately I didn’t take my camera to the party Thursday night at the Olympic Speed Skating Oval. The food was ok (it was the type of food that’s prepared for 2500 people) but the activities and atmosphere were pretty cool. I hear next year it’ll be on the east coast, hopefully I’ll be able to go.

Too Much Time?

Tuesday, September 2nd, 2003

Three day weekends generally mean more than usual free time (always a good thing).This last weekend was no exception and yesterday I got a little bored so I decided to play around with Amazon Web Services. First I got a developers token, then played around with the xml scratchpad to see what kind of information I could pull.

About the only useful thing I could think of was pulling an XML feed of my wish list and publishing it on my weblog homepage. After much php experimentation, I now have a nice listing of the items on my Amazon wish list. Will I keep it on the page? I dunno, I did it more to see if I could do it as opposed to actually wanting it on there. I haven’t used the wish list much anyway, most of the things on there were a little out of date so I went through and updated it (sort of). However, now that I have a good idea of how to manipulate XML data using php, there may be more…what’s the word…worth while? enhancements to come.

SCO and Hello World!

Friday, June 20th, 2003

I was reading an article today about the SCO/IBM lawsuit and thought to myself, what if SCO decided to seek a patent on the “Hello World!” code. All subsequent developers might be in trouble, but then again they could modify it to “Hi Universe!” or something. Hmm…that could be considered a derivative work, though. Software development sure is becoming complicated these days.

MovableType Permalink

Wednesday, March 26th, 2003

I’ve noticed on a few blogs, using movabletype, that have added a “Permalink” link at the end of their entry to link to the actual entry itself. This comes in handy when you want to link to an entry. In the past when I’ve done this, I’ve had a little trouble finding out what the link to a particular entry is. So, I figured I’d spend a few minutes today and try and figure out how to create a permalink for each entry on the index page and the category pages. Well…turns out they were already there to begin with. Apparently the default Movabletype template uses the time of the entry as a link to the permanent entry. I decided this wasn’t as intuitive as I’d like (since I never found it before), so I modified the following in my index template and category archive template:

<div class=”posted”>Posted by <$MTEntryAuthor$> at <a href=”<$MTEntryPermalink$>”><$MTEntryDate format=”%X”$></a>

to be:

<div class=”posted”>Posted by <$MTEntryAuthor$> at <$MTEntryDate format=”%X”$>
<a href=”<$MTEntryPermalink$>”>Permalink</a>

As you can see, I now have a nice “Permalink” at the bottom of each entry. Go ahead, try it out!

Coming Up for Air

Thursday, February 20th, 2003

It’s been a few days since I’ve posted an entry. Not because I haven’t had anything to say, just because I haven’t had the time to say it. All of my CS classes had projects due this week (1 on Tuesday and 2 on Wednesday). Now that I have them behind me I thought I’d take a minute to post. The project I did for my graphics class was kind of interesting. I wrote a program in C++ using openGL to draw a 3D sphere. Then added some functions to put the sphere in motion and have it bounce off the walls and such. We were only allowed to use the openGL functions to change the color and paint a single pixel. I added the ability to change the radius of the sphere, change it’s velocity components, add or take away gravity, etc. I also added a second sphere that would “cut away” part of sphere 1. All of this really wasn’t that hard to do, and I sort of enjoyed it.

I thought about posting the code for this but as is the case for most of the programs I write for my classes, I would never admit to writing such code. It’s a shame it has to be that way but it’s a result of the nature of the system. Specifically that mediocrity is passing. If I’m writing something for work or personal use I always take the time to make my code look nice and use proper structures and programming techniques. When it comes to my assignments for school…not so much (can you say global variables, and lots of them?). Maybe in the future I’ll take the time to rewrite this properly and post it. I’m sure all the future CS455 students would love that (assuming this will still be a required project).