Ray Tracing in JavaScript

I wanted to learn a little about ray tracing, and I’m kind of obsessed with javascript at the moment so i cranked out this little gem. I’m planning to add more features to it when I get a chance, but for now you can set the parameters for the sphere and location of the light source. Press ‘Trace’ to get an image on the canvas (which may take a few seconds).

SSH to same directory on remote server

My local dev environment matches the file structure of our dev server. Its convenient to be able to ssh to the same directory on the development server.

I added this to my ~/.profile.

function dev01 {
    ssh dev01 -t "cd $PWD; bash --login"
}

Then all I have to do is type dev01 on my local terminal and it opens a shell on the server in the same directory. If the directory is not found, it just drops you back into ~/

IDisposable as a Wrapper

I needed to make a bunch of webservice calls from a WinMobile 6 device. None of the calls are particularly heavy, but I wanted to give some feedback that something behind the scenes was going on, otherwise the user gets confused about why he can’t click on things.

My first iteration was this ugly custom Form that took two callbacks as parameters. The first call back did the real work, the second was called after completion so that the UI thread could do something with the results. It was verbose, ugly, unreadable, and confusing. Don’t do that.

Furthermore, it turns out all that marshalling data around between UserWorkItem threads and the UI thread made the service call appear to be taking far longer than it really was. Color me unsurprised.

Duh. Windows has had this ability for over a decade: the WaitCursor.

On a Mobile device, at least the model I’m using, this is rendered as a colorful spinner in the center of the screen. Moral of the story? Read the docs.

I didn’t feel like wrapping all the Service Calls with:

Cursor.Current = Cursors.WaitCursor;
callWebService();
Cursor.Current = Cursors.Default;

Talk about tedious. So I came up with this scheme:

public class WaitHelper : IDisposable
{
    public WaitHelper() { Cursor.Current = Cursors.WaitCursor; }
    public void Dispose() { Cursor.Current = Cursors.Default; }
}

Then to use it,

using(new WaitHelper())
{
    callWebService();
}

This has the added benefit that Cursor.Current will be set back to Cursors.Default inside a finally block, so even if the service throws, you don’t have to remember to set it back yourself.

This does however allocate a bunch of tiny, insignificant and data-less objects all over the place. Though perhaps the compiler or the jitter is smart enough to ignore it and inline the methods.

I don’t care though. I like it.

Migrating SVN Repositories

Create the new repository. I had to use my hosting provider’s control panel.

If you were naive, you  might think to just zip up an export of your project directory, move it to the new location, and check that sucker in.

But you would be wrong.

That would make you lose your revision history, which kind of defeats the purpose of having version control. Instead, you’re going to want to move the repository itself.

You’ll need to dump the source repository to a text file for later import. Windows, which lacks a lot of cool things out of the box, doesn’t give you the svnadmin tool. But no matter, if you’re using VisualSVN Server (which, if I recall, is about your only option on this platform), its included as part of the installation. You’ll need to change directories to the installation folder before running the dump command.

Oh, and you’ll need to be using an Administrator command prompt. If you can’t figure out how to open one, you probably shouldn’t be trusted with the company’s source control infrastructure.

On VisualSVN, by default, the repositories are all stored in C:\Repositories\ We’re going to dump the “project” repository to file.

cd "C:\Program Files (x86)\VisualSVN Server\bin"
svnadmin dump C\:/Repositories\project > c:project.txt

Then move that monstrosity to the new server using FTP, or a thumbdrive, or whatever other means are at your disposal. Finally, load it into the new repository:

~: cat project.txt | svnadmin load svn/project

svn/project is the directory where the repository will be stored. You chose this directory when you made the repository.

Bam. Now you’ve moved.

Hello World!

 

HelloWorld.cs
Console.WriteLine('Hello world!');
hello-world.php
<?php echo 'Hello World!'; ?>
hello_world.rb
puts "Hello world!"
query_hello.sql
SELECT 'Hello world!' FROM Cliches