Archive for the ‘Writing’ Category

Youtube Ripper: Collector’s Edition

Sunday, 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.

Another Attempt To Get WordPress Going With Atom 1.0

Thursday, 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.

Rewriting My Database Object

Wednesday, 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

Write Your Own Square Root Function

Wednesday, 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.

(more…)

Parallels Workstation Emulated Hardware Details

Tuesday, 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.

(more…)

Algorithm For Polygonal Numbers

Sunday, 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!

(more…)

Following Up On the Google Search Bar Issue

Saturday, 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.

No Borders With Beryl and NVIDIA AIGLX

Sunday, 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.

Screencasting and Youtube Compliant Encoding

Sunday, 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.

(more…)

Calculating the Number of Digits in an Integer

Friday, January 19th, 2007

Sometimes it can be handy to calculate the number of digits in an integer for various mathematical calculations.

(more…)

A Few Thoughts on Encoding

Saturday, 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.

(more…)

Time for Diagnosis Version 2.0

Saturday, 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.

Evaluating HTTP Responses in PHP

Saturday, 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.

(more…)

Rescuing Files From a Corrupted NTFS Partition

Friday, 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.

(more…)

Making The Google Custom Search Bar XHTML Compliant

Sunday, August 6th, 2006

Google has offered a customized search bar for webmasters to add to their page for quite some time now. But like many other things from Google the code they give you is old deprecated HTML, this is very likely to cause trouble for newer sites that are trying to make their documents XHTML compliant.

If you take a close look at the code Google gave me when I wanted to add my own custom search bar (use your browser’s “Show Source”-feature) you’ll notice many deprecated techniques like: tags are written with CAPS, not appropriate ending of tags, style information embedded into the tags, etc.

It isn’t very hard to fix it and make it XHTML compliant, but if you would like the solution right away you can check out how I solved it (”Show Source” again). And it now validates as XHTML 1.0 Transitional.

Note: Of course you should change the values to match your URL!