Screensaver Preventer

18 08 2010

I know what you’re thinking already: “just disable the screensaver in Windows preferences!” But what if you’re working on a computer which doesn’t allow you to change this (perhaps a work computer that’s locked down by Windows group policies…)

Well, here’s a small little program that checks the Windows Group Policy for the screen saver’s timeout which is usually ScreenSaverTimeOut in the registry:

 HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Control Panel\Desktop

It defaults to a 10 minute time-out if it can’t find the value from the registry.

Then, when it’s t minus 30 seconds until your screen saver is supposed to kick-in, the program “presses” the up arrow which resets Window’s idle time counter.

This runs very quietly in the system tray, and allows you to enable/disable/quit it with a simple right click menu.

Nothing too fancy.

Here’s a link to the executable: Download


Fash – A Bash-like Unix shell

10 06 2010

For my Operating Systems course, our main course-long project was to implement a very light, simple Unix shell, written in C. I took it a step (well…multiple steps really) further and added many of the most useful features of Bash, the most popular Unix shell. I titled mine Fash – the Fritz Again Shell.

I’m going to add the source code to a Git repository so anyone can view the source (give me about day or so).

Features of Fash:

  1. Ability to import settings in a .fashrc file
  2. Support for aliases
  3. Bash-like command history management/navigation
  4. Directory history management/navigation (similar to command history)
  5. Simple redirection (input from file, output to file, append to file)
  6. Supports piping (form of redirection really)
  7. Very basic tab completion
  8. Very basic “C interpreter” (allows you to quickly write a C program and run it from within the shell, but very limited

It’s pretty stable despite the large feature set (when I say large, I mean large for one man to implement in the course of a few months). And depending on what features you use in Bash, the Fash shell could serve as a lightweight replacement. All the source files combined are only 50KB (unless you count the hash-table library which adds another 64KB) and the executable is only 37KB. This means that my Fash shell (although granted it’s feature set and stability is MUCH smaller than Bash’s) is 420x smaller than Bash (Bash’s source code is ~21MB).

Anyway, feel free to check-out the code as soon as I add it to the Git repository!

UPDATE: Alright, here is the link to the Git Hub repo:

Feel free to let me know how badly it sucks!

Google Chrome extension with Google JavaScript API

20 08 2009

I’ve been in a huge rant about the awesomeness of Google Chrome over the past few days, and it got me wanting to become a little more involved with the project. I set out to create a Chrome extension (which is still very dev-stage) that would show me one of my Google Finance porfolios in a scrolling ticker-like style.

Unfortunately, Google’s JavaScript client API for developing web applications is meant (as far as I know) precisely for web applications: ones that are run (hosted) on the web.

The problem is, since you have to be logged-in to Google Finance to grab portfolio data, you need to have Google allow your website to “access” your account ( and when you do, Google will redirect you to the originating site that was requesting access.

Well…thats fine and great if you can be redirected to. Chrome extensions can’t. They are simply HTML/JavaScript files on your computer.

Now I’ve managed to come up with a solution that unfortunately can’t really be used by everyone unless you have a Google Finance porfolio #3. The portfolio ID must be #3 for the time being, because that’s what’s hard coded in my extension. Despite this (hopefully temporary) drawback, it does still demonstrate my workaround to the API authentication problem.

First, I created an HTML site that uses the Google API to pull my stocks into a small little ticker.

You can view the website here:

NOTE: When you go to this site you will only see the Finance icon. To connect your Google Account and retrieve your data, first click anywhere on the page. This will try to log you in to your Finance account (don’t worry, I’m not stealing any personal information) and redirect you back to the site. After this, click on the Finance icon to retrieve your #3 portfolio.

Now that’s the majority of the work. Now to make it an extension, I created another file on my comptuer called “my_toolstrip_client.html” (as well as the neccessary “manifest.json” file) and here is the code:

<div id="my_toolstrip">
	<iframe scrolling="no" FRAMEBORDER="0" width="125px" style="margin-top: -3px;" height="40px" src="" />

You see, all the Chrome extension is, is an iframe to my site which serves as the extension, since my site can actually use the API. Now if you do all this and try to load the extension in Chrome. You’ll have to first go to the original site and click on the body to authorize access. Then you can click on the Finance icon in your Chrome extension and VIOLA! You have a scrolling ticker extension in Chrome.

I’ll be working on this for a while and adding some features. Hopefully soon I’ll be able to cycle through each of your portfolios and add all the different stocks from each one.

You’ll notice that right now, all the stocks are saying 0.0% I think there is something wrong with the Finance API because I’m just grabbing a field straight from the documentation for the Finance API. The only thing that seems to actual give any numbers is shares.

Here’s a screenshot:

Chrome extension

Adding XML element to existing XML document in C#

10 07 2009

I was looking around for a good tutorial/example on how to add an XML node to an exisitant XML document but never really found one that I needed. Here’s my version:

Let’s say this is your existing XML Document:

<?xml version="1.0"?>
          <add key="aKey1" value=""/>
          <add key="aKey2" value=""/>
          <add key="aKey3" value=""/>
          <add key="aKey4" value=""/>
               <add verb="*" path="*.vjsproj" type="System.Web.HttpForbiddenHandler"/>

And you wanted to add the following element under the <appSettings> section:

<add key="someKey" value="someValue" />

Here’s the C# code you’d need:

XmlDocument xDoc = new XmlDocument();
XmlNode xNode = xDoc.CreateNode(XmlNodeType.Element, "add", "");
XmlAttribute xKey = xDoc.CreateAttribute("key");
XmlAttribute xValue = xDoc.CreateAttribute("value");
xKey.Value = "someKey";
xValue.Value = "someValue";

And there you have it! Your XML file will now include your new node!

iPhone style checkbox in .NET

2 07 2009

I really like Apple iPhone’s “sliding checkbox” that you see everywhere. It’s much easier on the eyes and has a big “cool factor”. Now I’m not saying that all applications need a “cool factor” (especially the program I’m using this for), but every once in a while, it’s fun to add some cool things to a .NET application that you don’t get from the general toolkit.

Unfortunately, there isn’t anything that I know of that can give .NET controls a nice rounded corners, so you’ll just have to deal with the very squareish boxes in my example.

First, you need a form (obviously) and you’ll need to add a SplitContainer. You’ll probably have to go into the properties and change the “Dock” property to “None” (otherwise it fills your form). Also, you’ll want to change the “BorderStyle” to “Fixed3D”, set the “SplitterWidth” to half the width of the container, and set both Panels’ “MinSize” to “0”. Resize the whole container to the approximate size of the iPhone checkbox, and set the ‘BackColor” to white, or an offwhite. A good size would be around (65,22), but for my demonstration, I’m making mine larger.

Also, add a Label to each panel. The one in the first panel should have a blue color that is similar to the blue in the iPhone version, and the Text should be “ON”. You’ll also want to change the “Dock” for both Labels to “Fill”

The Label in the second panel should be the same color as the container backcolor, and should say “Off”. You’ll probably want to change the font in each Label, and set the “TextAlign” to “MiddleCenter”

Also, change both Labels to AutoSize = False

Here’s what it should look like so far (it looks like “O” is the only thing in the second Label, but its just being crunched because the splitter is in the middle of the container):

Now we need to add some action, so first double click on the form to bring up the “Form Load” event handler.

You’ll need to add the following (assuming you didn’t change the names of the controls):

private void Form1_Load(object sender, EventArgs e)
	splitContainer1.SplitterDistance = 0;
	splitContainer1.SplitterMoved += new SplitterEventHandler(splitContainer1_SplitterMoved);

This assures that when the form loads, the container will be set to “O00”. It will be giving you an error about the method not existing or something; just ignore it.

Now we need to add some click handlers for each Label. You’ll need to double click the first Label and add this code:

private void label2_Click(object sender, EventArgs e){splitContainer1.SplitterMoved -= new SplitterEventHandler(splitContainer1_SplitterMoved);for (int x = 100; x >= 0; x--){splitContainer1.SplitterDistance = x;splitContainer1.Refresh();//Thread.Sleep(1);}splitContainer1.SplitterMoved += new SplitterEventHandler(splitContainer1_SplitterMoved);}
private void label1_Click(object sender, EventArgs e)
	splitContainer1.SplitterMoved -= new SplitterEventHandler(splitContainer1_SplitterMoved);

	for (int x = 100; x >= 0; x--)
		 splitContainer1.SplitterDistance = x;

	splitContainer1.SplitterMoved += new SplitterEventHandler(splitContainer1_SplitterMoved);

Now go ahead and double click the second Label (O00) and add this code:

private void label2_Click(object sender, EventArgs e)
	splitContainer1.SplitterMoved -= new SplitterEventHandler(splitContainer1_SplitterMoved);

	for (int x = 0; x <= 100; x++)
		splitContainer1.SplitterDistance = x;

	splitContainer1.SplitterMoved += new SplitterEventHandler(splitContainer1_SplitterMoved);

Note that depending on your size, you will have to change that “100” in each of the loops to the width of your container divided by 2. (my container is 200 wide, so my loop has 100)

You may be wondering why I am removing and re-adding the SplitterEventHandler. It’s because if we didn’t do that, every time you try to update the splitter’s distance, it would raise the splitter moved event, which we don’t want, since we only want the user to be able to raise that event when they are dragging the splitter manually.

Now we are going to add the event handler for the splitter. Here’s the code:

private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
	if (e.SplitX > 50)
		splitContainer1.SplitterMoved -= new SplitterEventHandler(splitContainer1_SplitterMoved);
		for (int x = e.SplitX; x <= 100; x++) 		{ 			splitContainer1.SplitterDistance = x; 			splitContainer1.Refresh(); 		} 		splitContainer1.SplitterMoved += new SplitterEventHandler(splitContainer1_SplitterMoved); 	} 	else 	{ 		splitContainer1.SplitterMoved -= new SplitterEventHandler(splitContainer1_SplitterMoved); 		for (int x = e.SplitX; x >= 0; x--)
			splitContainer1.SplitterDistance = x;
		splitContainer1.SplitterMoved += new SplitterEventHandler(splitContainer1_SplitterMoved);

That should do it folks! Run your application and viola, a working iPhone style checkbox in .NET. Now if you want to know what the value is (ON or O00) you’ll have to check whether the splitter is at 0 or 100. if it’s at 0, its o00, or if its at 100, its on.

In the download below, I added a Label that tells whether it is ON or O00.

If you wanted to be really fancy, you could create a custom .NET control called IPhoneCheckBox that extends the SplitContainer control and had an custom enumeration specifying whether the control is set to “ON” or “O00”. It would require a little more code, but it really wouldn’t be that hard. If anyone asked for it, I’d give a tutorial on that too.

Have fun!

Here’s a link to the compiled EXE. All it is, is a checkbox, so I don’t think you’ll have much fun with it, but it will allow you to see the final results.

Download ZIP containing the EXE

Awesome internet connection

2 07 2009

So I did a recent speed test of my internet at the company where I’m working for the summer. Pretty nice…


Browser speed and compatibility comparison

1 07 2009

I was arguing with a friend on Facebook about why Chrome is better than Firefox. I won the argument until he came back a day later saying the new Firefox 3.5 was definitely faster than Chrome. I decided to do some tests just to prove him wrong.

Here are my results for running the SunSpider JavaScript benchmark across 5 different browsers (the latest verions of each) as well as the infamous Acid3 test.

UPDATE: I’ve also added results from the V8 benchmark test.

UPDATE: Google Chrome’s latest 4.0 build is almost 2x as fast in the SunSpider test! OMG! Also, Acid3 linktests no longer fail!

Chrome (Official Build 23680)

SunSpider: 510.2ms

Acid3: 100/100

V8 Benchmark: 3796


Safari 4.0 (530.17)

SunSpider: 1382.4ms

Acid3: 100/100

V8 Benchmark: 2074


Firefox 3.5

SunSpider: 2229.8ms

Acid3: 93/100

V8 Benchmark: 383


Opera 10.0 Beta 2

SunSpider: 4333.4ms

Acid3: 100/100

V8 Benchmark: 200


Internet Explorer 8.0.6001 (18702)

SunSpider: 6582.6ms

Acid3: 20/100 (Linktest and others fail, along with IE warning you about running an addon…just a mess)

V8 Benchmark: First, an alert about an unresponsive script, then after about 20 seconds, 55.6


Clearly, Chrome is the obvious winner. It’s 2x faster than Firefox 3.5 and much faster than every other browser (although Safari 4 is pretty close).

I use Chrome as my main browser, although I still keep Firefox around just for it’s FireDownload addon which seems to drastically speed up download speeds. I could start downloading something in Chrome (large file), wait a few minutes, wait for Firefox to open up, start the download with FireDownload, and have it finish way before any other browser was even half-way done downloading.

I’ll also be keeping my eye on Opera 10’s new Unite service, which promises to be a revolutionary way to interact with the web. I’m just going to like because I’ll be able to listen to my music library anywhere on any computer.

(Images from Wikipedia)