Down the Microsoft Rabbit Hole

| No Comments | No TrackBacks

Usually I'm in Oracle land at my job. I'm happily running queries through my Oracle client, the birds are chirping, and the air is sweet with the smell of flowers.

Today, though, I came up against the behemoth that is SQL Server. We are in the midst of installing a third-party application which uses SQL Server. Part of my job is to take the relevant data out of SQL Server, copy it to our Oracle database, and then back again as things change. I'm writing a synchronization script. To do this, I had to install the client for SQL Server, which is SQL Server Management Studio 2008, on my Windows XP box.

The SQL Server client is a free install from Microsoft, so I headed over to their website to download it. No problems there, once I found the file that matched my OS and processor. I opened up the download and discovered that I needed to run a hotfix for my copy of Windows XP before installation. OK, I can see the point of that. I ran the hotfix and rebooted my PC. Then I tried to run the SQL Server client install again. No dice. I needed to install Microsoft PowerShell.

So, I head over to the PowerShell page, but that requires Silverlight for Microsoft to verify my system before they allow the download to happen. Of course, I didn't have Silverlight installed because I was running Firefox. I started up Internet Explorer, went to the page again, and found out that I really don't have Silverlight installed. Sigh. Another download, install, and reboot, and I was ready to install PowerShell. Again, another download, install, and reboot and I was ready to install SQL Server client.

Once I got through all that, I started the installation of SQL Server client and went to lunch. I'm not sure how long the install took, but when I got back a half-hour later it was finished. And asking for another reboot. Finally, after 3 hours (including lunch), 4 reboots, and 4 software installations, I had SQL Server Management Studio 2008 installed.

That's when it hit me: software should be easy to install and should determine and install its own pre-requisites. Please, Microsoft, fix your process! I'm Steven and I'm not taking any credit for Windows 7.

Managing Windows Folder Permissions from ColdFusion

| No Comments | No TrackBacks
Last week I got an IM from one of the system administrators at my job. He was trying to install ColdFusion 9 on a 64 bit test server, but the install kept failing because of some old DLLs that we use to manage Windows folder permissions. I tried to recompile the DLLs for a 64 bit machine, but the code was pre-.Net and wouldn't compile nicely. I could either spend days getting it to compile or spend the time writing a new DLL in .Net. I chose to write a new library.

Garbage Collection in ColdFusion

| No Comments | No TrackBacks

Recently I've been developing an application in ColdFusion to load records into a database for my job. The script takes so much memory that I've had to implement several schemes to keep the memory usage down. The main problem seems to be that full garbage collection doesn't happen by ColdFusion until the entire request page has been loaded. This works fine for web pages, but not so well for pages that are meant to be scheduled batch jobs.

One solution that I came up with is running the garbage collection manually on a set interval. The interval that I chose was every 1,000 records processed. To implement that, I just call my function with the current row count: cleanupMemory(myQuery.currentRow) and then only call the garbage collector if myQuery.currentRow mod 1000 eq 0. In my code, 1000 is represented by the constant CLEANUP_INTERVAL.

A Quick Database Rant

| No Comments | No TrackBacks

My job has me collecting data from a warehouse in another part of the university and using that to build a local web application. Some of the data that I'm working with are addresses. Users can create home address records, business address records, and flag one of their addresses as their preferred address.

Some ways to store the preferred address decision in the database are by having a preferred flag on each address record, or having a separate preferred_address table where the id for each user's preferred address is kept.

The way the schema I'm working with handles it is by making "preferred" an address type, along with "home" and "business". That leads to duplication of data, since everyone's preferred address is going to be one of the other addresses in the system. So now for every user, there are two address records with nearly identical data (the only difference is the address type). One record might say "home" and the other says "preferred".

Getting Started with Visual Studio

| No Comments | No TrackBacks

When I've developed non-web applications, I've always used a Linux, Unix, or a Mainframe system. Even though my current job has me developing web apps to run on Microsoft's IIS web server, I still do my development in a mixture of Cygwin and Eclipse. I really don't have any experience developing with Microsoft's tools or with the .NET environment.

For 2010, I'm committed to learning about Microsoft's development tools and the .NET environment. To start with, I have Visual Studio 2008 installed on my PC.

I've been reading the book Coders At Work and I've noticed a lot of discussion in the book about the importance of reading code from other programmers. I forget who in the book said it, but someone said the best way to start reading someone else's code is to first get their code to build. So on that note, I'm trying to build Firefox in Visual Studio 2008.

The first step is prerequisites. According to the Mozilla Windows Prerequisites, I need to have the correct Windows SDK and the MozillaBuild suite installed.

Installing the MozillaBuild suite is very straightforward. I follow the link to download MozillaBuild Version 1.4 and executed the file once the download was complete. It setup a bunch of Unix tools on my system that Firefox needs to properly compile and provided a .bat file which would configure the correct environment variables to use those tools.

Next is the Windows SDK. According to Mozilla's instructions, I need to download and install the Widows 7 SDK. Again, that's a simple download and execute to install, though the actual install takes significantly longer than the MozillaBuild install.

Finally I'm ready to download the Firefox source code and give it a first try and installation. More on that as this project develops...

Project Euler 25 in Lisp

| No Comments | No TrackBacks

It's been a while since I've written anything here. A lot has been happening in my life that has taken me temporarily away from programming for fun. So I thought I'd jump back in with a small and simple program in Common Lisp. Problem 25 at Project Euler fits the bill perfectly. Here's the problem description:

The Fibonacci sequence is defined by the recurrence relation:

F(n) = F(n−1) + F(n−2), where F(1) = 1 and F(2) = 1.

Hence the first 12 terms will be:

F(1) = 1
F(2) = 1
F(3) = 2
F(4) = 3
F(5) = 5
F(6) = 8
F(7) = 13
F(8) = 21
F(9) = 34
F(10) = 55
F(11) = 89
F(12) = 144

The 12th term, F(12), is the first term to contain three digits.

What is the first term in the Fibonacci sequence to contain 1000 digits?

My solution in Common Lisp is:

(defun fib-term-at-length (limit)
    (labels ((fib-next (n a b)
        (if (= limit (length (write-to-string b)))
            n
            (fib-next (1+ n) b (+ b a)))))
        (fib-next 1 0 1)))

(fib-term-at-length 1000)

I wrote a function that takes the term limit as a parameter. In this case the term limit is 1000 since we're searching for the 1000th term. The function uses the labels function to setup a subroutine named fib-next that is lexically scoped inside the fib-term-at-length function. This means that the function fib-next can only be called from within fib-term-at-length and not from anywhere else. It's a way to keep the global scope clean.

The fib-next function is recursive. It takes the number of the highest Fibonacci term calculated as input, along with the previous two Fibonacci numbers, and returns the term number if the highest Fibonacci term, b matches the term length, n. Otherwise it calculates the next Fibonacci term, increments the term number, and calls itself again. To determine how many digits the Fibonacci number has, the number is converted to a string and then the length of the string is determined.

The power of Lisp is that this program took me about 5 minutes to write. It's a great way to jump back into programming. The longest part of writing this was the time I spent looking up the function to convert a number to a string. Part of the reason I could develop this so quickly is because Lisp doesn't have an upper limit on integer size. If I were writing this in C, I'd have to store each Fibonacci number as an array because the standard int isn't large enough to store 1,000 digit values. Even a long long can't store 1,000 digits. Then I'd have to write functions to perform arithmetic numbers that are stored in arrays. Or more likely I'd use a third-party library that was built to handle large numbers. But Lisp is able to store arbitrarily large integer values without a problem, as long as the computer's memory can hold them. It's nice to have a programming language that works with you.

Restricting Checkbox Choices with jQuery

| No Comments | No TrackBacks

I think I've mentioned before that I work as a web applications developer at a university. Since the fall semester started, I have been very bust at work. Like every other school out there, we are making contingency plans for students or instructors who contract the H1N1 virus and have to miss one or more classes. That means I'm making modifications to the course management software, as well as fixing any bugs the pop up from the updates we installed at the start of the semester.

One of the H1N1 modifications is giving the instructors the ability to have their courses recorded but not allowing the students to access those recordings. Our process has always been that class recordings are always posted to the course management software for the students to listen to online. Each semester some instructors decide to not record their courses, which is fine. But, in the current situation where students might miss a week or more of all their classes, we wanted to given instructors the option to record their class and to restrict access to that recording. A private recording, if you will, which can be given to selected students.

A Stack Tutorial in C

| 3 Comments | No TrackBacks

Stacks are a common data structure in computer science. They work in the same way as a pile of cafeteria trays – you can remove one from the top or you can add one to the top, but you can't get anything from the bottom of the pile without removing everything on top of it. The computer science term for "adding to the pile" is push and for "removing from the pile" is pop.

Most languages have either stacks or something that can be coerced into acting as a stack built into the language. C does not. In C, you need to build your own implementation of a stack before you use it.

I was working a program to solve the blocks problem on the UVa Programming Challenges website. Basically the problem states that you are given anywhere from 1 to 25 stacks each with one block in the stack. You also are given a set of commands to move these blocks from stack to stack. The problem is to write a program that interprets the commands given and moves a collection of virtual blocks.

Sounds like a great place to use the stacks data structure, right? I thought so, too. The program that UVa uses to check the correctness of solutions doesn't allow external libraries, so I needed to write my own stack implementation. I looked around the Internet and didn't find any good stack tutorials. That's when I decided to post about stacks.

Movable Type

| 1 Comment | No TrackBacks

I've moved my blog from WordPress to Movable Type. Basically WordPress was not handling requests fast enough for me. Movable Type publishes all blog entries to HTML pages instead of fetching them from the database for each request, which makes it much more responsive than WordPress. Of course, the trade-off is that posting an entry becomes much slower, but I'll take that trade-off.

I was using a WordPress plugin to handle syntax highlighting, but since the plugin was written in PHP and Movable Type is in Perl, I can't use the same plugin. I found Google's Prettify project, which is a syntax highlighter, written in JavaScript, that is used on code.google.com. To use Prettify in Movable Type, I just added the following lines to the HTML Head template:

<!-- Added for Google prettify -->
<link rel="stylesheet" href="/prettify/src/prettify.css" type="text/css" />
<script type="text/javascript" src="/prettify/src/prettify.js"></script>
<script type="text/javascript" src="/prettify/src/lang-lisp.js"></script>
<script type="text/javascript" src="/jquery/jquery-1.3.2.min.js"></script>
<script type="text/javascript">$(document).ready(function() {prettyPrint();});</script>

Google's documentation says to call the prettyprint() function in the page's onload event. Instead of modifying every <body> tag in Movable Type's template, I chose to import the jQuery library and use $(document).ready() event handler to call the prettyprint() function on every page in the site. Once again, jQuery is making web development easy.

Very busy

| No Comments | No TrackBacks

I work at a university developing web applications for students, faculty and staff. Mid-July through September is crunch time for me at work. Right now I'm busy building a portfolio application for students where they can upload their work, document the activities and groups they participated in at school, track their graduation requirements, and in general, create a document they can carry with them after graduation.

I'm building the application in ColdFusion and jQuery. A lot of what I'm using jQuery for is tab widgets and Ajax functionality, neither of which degrade gracefully in ColdFusion 8. But, the application is on a tight deadline (must be working in production by the time school starts), so for now I'm focusing 100% of development efforts on this app, which means there probably won't be any code-related posts here until closer to the semester deadline.

Find recent content on the main index or look in the archives to find all content.

Recent Comments

  • Josefina Wheller: I dont usually bother to submit comments on peoples sites, read more
  • Zona Libre: Hello. Fantastic job on http://www.fluentincode.com/2009/09/stacks-in-c.html, if I wasn't so busy read more
  • fanta: Thanks a lot, mate. You really helped me understand stacks. read more
  • Chris Herdt: I've been torn between MovableType and WordPress lately myself. I read more
  • Aristotle Pagaltzis: Good post. Note that you can write the Perl version read more

Recent Assets

  • stackNode.png
  • emptyStack.png
  • Steven Tomcavage
Creative Commons License
This blog is licensed under a Creative Commons License.