May 6th, 2007
The idea of caching is to keep a replicate of data where it is easier to reach than the original. Simply put caching could mean to keep a static copy of a web page that would otherwise be compiled together using a dynamic procedure (like PHP using a database back-end). By caching a copy to be served statically the overhead the dynamic procedure would otherwise create is eliminated.
A very simple cache procedure would consist of checking if there is already a cached copy of the requested material, if there is no already cached copy then it should create one. The second thing to take into consideration is how ‘fresh’ the currently cached copy is, all file systems today keep track of modification times on each file, comparing timestamps is sufficient enough for this. This very simple example does the previously mentioned checks and comparisons and you can try it out by accessing a cached copy of this post.
Since there is still some overhead when the client has to load the CSS and associated images the bandwidth saving is non-existent, the database load is totally eliminated however. I intend to work further on this caching code and make it object oriented and later on figure out how to make it save some bandwidth as well as database queries and execution time.
Posted in Writing | 1 Comment »
April 8th, 2007
Unfortunately, this script is broken now. Youtube changed things internally and the script broke. For a working script, see this post
Today I had an interesting conversation with my fellow blogger themak and he asked if it would be possible to download a bunch of videos that he knew followed a regular naming scheme and that were uploaded by two different users. After some coding I came up with a script that will download all videos uploaded by a specific Youtube user where the title matches a pattern (regexp compatible). The final output is flash videos named after the unique video ID.
$ sh youtube-user.sh rpoland "Andy Mckee"
Would download all videos with Andy Mckee in the title listed on the user rpoland’s profile page.
Update: Mike wrote a PHP port!
Update again: Regarding the Digg comments, the script now works with all profile pages and I re-wrote it to feature functions instead of one big one-liner.
Hopefully last update: Fixed the last regexp flaws and removed a flag to xargs that stopped it from running on OS X. Also added a dry-run mode.
Posted in Writing | 122 Comments »
April 5th, 2007
The previous post included a patch that turned out to be invalid for the newer wp-atom.php shipped with the 2.0.x versions so I decided to fix my own feed to validate correctly a long with publishing the whole file this time. One remaining issue is that the validator will complain about inline CSS and other things it thinks might be dangerous or mess up the feed reader.
Escaped HTML in titles are still not functional, the original file tried to put the title attribute mode to escaped but that didn’t seem to follow the Atom standard.
Posted in Writing | 1 Comment »
April 4th, 2007
As part of my combined programming and database course I decided to approach the remaining exercises in a more object oriented way by using a database class to handle the connection towards the database. The first version was somewhat clumsy since I wanted to put in so many features into it. Tonight I sat down again and re-wrote the whole thing from scratch with simplicity in mind and the result was 300 lines less code even though I added some remarkable features the previous incarnation didn’t have.
If you’re interested in what it looks like the source code is available on a subdomain of mine along with another file showing off some example usage
Posted in Writing | 1 Comment »
April 4th, 2007
Ever wondered how your calculator calculates the square root for a given number? It probably uses power series but an easier to grasp approach is the following:
- Take a number t
- Let r be your guess of what the square root might be
- After that repeat the following a few times: r = (r+t/r)/2.0
- r will now be a number pretty close to the square root of t
Below are two version of what this would look like in Python and C++. The initial guess is half the number t.
Read the rest of this entry »
Posted in Writing | 1 Comment »
April 3rd, 2007
An annoying thing about emulators is that most emulators emulating PC hardware aren’t that detailed about what hardware they are actually emulating. This post summarizes the hardware emulated by a typical Parallels Workstation 2.2 installation by listing the output of various utilities.
Read the rest of this entry »
Posted in Writing | No Comments »
April 1st, 2007
Today I decided to put together a PDF-document of something I have been playing with for quite some time. Just like the title of this post suggests the paper is on the topic of polygonal numbers, or to be more specific on the topic of testing numbers to see whether they are polygonal or not. The paper starts with a clumsy rewrite of the traditional definition of a polygonal number and ends with Python source code for testing any integer for s-gonal properties!
Read the rest of this entry »
Posted in Writing | No Comments »
March 31st, 2007
A few months back I posted some example code for an XHTML compliant version of the Google custom search bar. The version that was given to me by default validated with no more than 56 errors (see the full story here).
After taking out the specific variables from the code I had modified I managed to mash up a template to use for generating new search bars and the result is another Google search bar generator but this one will give you an XHTML compliant output.
Posted in Writing | No Comments »
January 28th, 2007
If you find that you have no borders after you have set up Beryl with AIGLX using the latest nvidia driver you should append the following to your /etc/X11/xorg.conf in the “Device” section:
Option "AddARGBGLXVisuals" "True"
Option "RenderAccel" "True"
Option "AllowGLXWithComposite" "True"
Option "backingstore" "True"
Option "TripleBuffer" "True"
For some reason many guides do not mention this problem.
Posted in Writing | 41 Comments »
January 28th, 2007
This article will guide you through the process of setting up the screencapture software recordmydesktop, record a screencast and convert it to a Youtube ready format for release to the public. The video converter used will be mencoder, already in the package repositories for a wide range of Linux distributions. Because the recording software is currently not available as a package for the distribution used in this article (Ubuntu Edgy Eft) it will feature a section on how to grab the latest source code and build it yourself.
Read the rest of this entry »
Posted in Writing | 8 Comments »
January 19th, 2007
Sometimes it can be handy to calculate the number of digits in an integer for various mathematical calculations.
Read the rest of this entry »
Posted in Writing | 7 Comments »
January 13th, 2007
The following article is a brief summary of different approaches of music file encoding I’ve used and a few thoughts about how to put them to use. Various encoding utilities such as lame, oggenc and flac are used throughout this article.
Read the rest of this entry »
Posted in Writing | 2 Comments »
January 6th, 2007
Since the release of Diagnosis 1.2 (17th of July 2006) the plugin has been downloaded over a thousand times (or 1052 to be correct, when I’m writing this). I would like to thank the WordPress Podcast for mentioning the plugin in . A big round of applause to Charles Stricklin for his work and dedication to the community podcast.
For a long time now, nothing has happened to the original version written last summer. That however, is about to change. I intend to sit down at the drawing board once again and plan the future of this little plugin. The main purpose of this will be to maintain a functional plugin now that WordPress is moving towards version 2.1. I also see this as a small challenge for myself since Diagnosis was the first thing I ever wrote in PHP and it will be so much fun to see how I have grown as a programmer.
Posted in Writing | 3 Comments »
January 6th, 2007
Sometime it is valuable to check the HTTP response of a HTTP-request for quality and service availability assurance. The following code returns the headers given in response to a HTTP-request.
The following code opens a socket connection to a hostname or IP address (mandatory argument) and sends the request (mandatory argument). After that it returns the HTTP response code as a string.
Read the rest of this entry »
Posted in Writing | 11 Comments »
August 18th, 2006
Yesterday a friend called and told me that one of his machines had faced a harddrive failure. The disk in question was an IBM Deskstar, ironically referred to as the IBM “Deathstar”. Windows couldn’t do much about it so he brought it to me so I could have a look at it.
Linux has excellent NTFS-support these days so the first thing to do was to try a simple mount, that however, resulted in I/O Errors and several warnings. To locate the exact failure point of the harddrive I started making a raw copy of the partition (the disk had one big 40GiB partition on it) using dd. After 35GiB the I/O Errors were once again present.
None of the Live-CDs I had collected throughout the years had utilities for actually checking or fixing NTFS file system problems, so I stumbled upon the Trinity Rescue Kit in my search for such a thing. The small ISO-image (about 85MiB) contains two different anti-virus utilities and a collection of NTFS file system tools (and a lot more), and was therefore suitable for my needs.
Read the rest of this entry »
Posted in Writing | No Comments »