A very cool article on bit operations. Samples provided using C language, but overall the article is language agnostic. Easy to read and very informative.
Tuesday, September 29, 2009
Thursday, September 24, 2009
Online tools for Regular Expressions
This site is very useful and performs well. Lets you test the expresson, view matches, and replace string elements. Not pretty, but performed flawlessly.
This one looks interesting but I've found the performance a bit twitchy. Still, it lets you visually examine your expression and can probably help you find some syntax errors quickly. It's probably going to be worth re-visiting this site to see how it grows.
Sunday, September 13, 2009
Semicolons in javascript
So, after examining some Google code I found they use semicolons more for statement delimiting than termination. Last statements in a code block are not semicolon terminated, only preceding code lines are. This got me searching for the meaning of semicolon in javascript. I found many sites stating it is optional, and many sites which warn of the danger of following this practice.
Although the script interpreter will insert semicolons at the end of lines, this may break down if the script is stripped of all needless white space. Therefore a good rule of thumb seems to be to put semicolons at the end of lines to clearly indicate the end of statement. Google's practice of using semicolon as statement delimiters seems to be adequate as well.
On a related topic, i have also found some advice for properly formatting javascript code because the interpreter will insert semicolons where it thinks appropriate. This is something I was not aware of before and knowing this now will probably help debug some code down the road.
Thursday, December 25, 2008
Simple (and accurate) countdown timer in JS
Sample countdown timer:
The above example is a simple and straightforward implementation a javascript countdown timer to a future event. The script will use the computer's internal clock to calculate the time so it will be accurate no matter how long it runs (at least down to the second). The time is calculated using epoch time and the following calculation:
As you can see, the only requirements are that we know the target time and the current time. Current time is easy, and can be obtained using the following code:
The target time you either already have as input, or as in the example below, you calculate it based on the current time plus the remaining time. Here's the full body of the javascript method.
// the input time below is 1 day and 15 seconds var timeleft = 86415;
In the html document body I have defined a span of id "mytimer", and the javascript method displays the countdown timer as above.
I should note that this script has only been tested in Firefox, I don't know if it will work in other browsers. Also, please note the example has seconds resolution, not milliseconds (to get milliseconds, don't divide the epoch times by 1000). That's all, this script is simple, but that should now allow you to take it and improve it as you may see fit.
Monday, November 03, 2008
Adding new hard drive to Linux
Dead simple instructions for adding a new hard drive to an existing linux system are here.
I used GParted instead of fdisk and mkfs to partition and format the new drive.
Saturday, September 20, 2008
X on RADEONHD with two monitors
Technical details:
- Linux version 2.6.24-1-686 (Debian 2.6.24-7).
- X.org X Server version 1.4.2.
- Video chipset is ATI Radeon HD 3650
- I am running with the testing (Lenny) packages
The following xorg.conf file is what I am currently running with, it is sufficient for providing me with an X desktop spanning both my displays.
Configuring X on a new box was relatively easy. After the new hardware was all in place, and the latest ati driver downloaded, I backed up the original xorg.conf file and run:
This created a vanilla configuration which got the X server up and running, although the desktop was mirrored across both displays. The next step is to configure dual display to emulate one large screen. For this you will need the xrandr tool, which is part of x11-xserver-utils.
After you have the tools installed, run xrandr at the command prompt, this should give you an output similar to the following:
In my case, I have two monitors connected, DVI-I_1/digital and DVI-I_2/digital. Keep those names handy, you will need them later on. Next, we need to define both monitors in xorg.conf. This is done through the "Monitor" sections in the file. I defined "Monitor1" to be "RightOf" "Monitor0". If your configuration is different, you can reverse that. . . or swap monitor cables at the video card.
With the monitors defined, we attach them to the video card through the "Device" section. Notice the monitor labels are the name as is used by xrandr AND prefixed with "monitor-". This is important and took me a while to figure out.
Now we define the screen through the "Screen" section, this defines the geometry. With older versions of X I had to be pretty explicit here how the screen was to be emulated. With the latest version I just need to identify the graphic device which is driving the display.
This is it, when X restarts, it will now come up with one large virtual screen. If this worked, only one of the screens should now have the login prompt.
Final notes: the RADEONHD driver is still in it's infancy; DRI is not yet supported, so it has no 3d capabilities. You can also use the graphical interface to xrandr to configure multi display after you log into X. It's quick and easy although not permanent - you will need to repeat the task when you re-start X. The tool is called "grandr" and is contained in a debian package by the same name.