A place for my programming projects and the occasional blog about technology related matters.
Subtitle Fixer
Author einar | 20.03.2008 | Category code, python, utilities
I was watching a movie on my computer the other day and I had gotten the subtitles for it off the internet, I think from http://opensubtitles.com or something like that. The only problem was that they were a bit out of sync with the picture, about 2 seconds too late. Using a good media player, such as VLC you can add an offset to the subtitles every time you watch the movie but I figured I could probably whip up a small script to do it for me so I could just do it once and then have the subtitles correct every time I watched the movie. Read More…
Binary Tree Image
Author einar | 20.09.2007 | Category C#, code
Recently I had a school project where we needed to parse a certain grammar into a syntax tree and do some analysis on the code. Everytime I’ve had to work with trees (which has only been for school projects actually) I’ve been frustrated because it can be hard to visualize the tree, especially when it starts getting large. I’ve pretty much done two things in that situation, either draw the tree on a piece of paper, which takes a lot of time and is very boring, or try to look through the structure in the debugger, which gives you some idea but is not really very convenient. So, when I was working on this new project I figured I could probably come up with some simple way of displaying the tree while I was working on it. I wanted the solution to be re-usable so I could pull it out again the next time I have to work with binary trees without having to change it to match the new project. So, here’s what I came up with.
Read More…
Run Windows Service as a console program
Author einar | 15.08.2007 | Category C#, code, tips & tricks
Visual Studio and the .NET framework make it really easy to create Windows Services. All you have to do is create a new project, select ‘Windows Service’ as your project type and you’re all set. However, debugging Windows Services in Visual Studio can be a big pain. The recommended way is to use InstallUtil to install them, and then restart the service and attach the debugger everytime you want to debug it. I wanted Windows Live! Bot to be available as a Windows Service, but I also wanted to be able to debug it without the hassle, so here’s what I came up with: Read More…
Export Haloscan comments
Author einar | 13.08.2007 | Category code, haloscan, python
A few weeks ago I was helping my sister change her blog. She has a Blogger account but uses Haloscan for comments, since when she started blogging Blogger didn’t offer comments as a part of their service. That has changed now, so I thought it would be much more convenient to have the comments and blog all at the same place. I just needed a way to export her Haloscan comments and import them into Blogger. So I wrote a small Python script to do the exporting for me. Read More…
Who has deleted you from MSN?
Author einar | 09.08.2007 | Category C#, code, msn
My wife showed me a website the other day where you could type in your email address and password for MSN Windows Live! Messenger, and it would show you which of your contacts didn’t have you in their contact lists, either because they’d never added you, or because they’d deleted you at some point. It’s a cool idea and a good way to prune some of the contacts that you never speak to from your contact list. But I don’t really wanna give up my user / pass to some third-party site, even though they promise not to log it anywhere, and most of these sites (at least the ones I saw) tried to make some money by sending advertisements to your contacts while they were checking them, which I definitely didn’t want. So, since I already have a project that uses the MSN protocol I figured I could probably whip something up myself. Read More…
Using Wordpress authentication in Zenphoto
Author einar | 08.08.2007 | Category code, wordpress, zenphoto
In a previous post I talked about how to integrate ZenPhoto into Wordpress. After I had done that for my own site I still wasn’t happy. I didn’t like the fact that I had to use seperate logins for Wordpress and ZenPhoto, I wanted this to be as integrated as possible. So I figured out a way to make ZenPhoto ask Wordpress for authentication credentials. In other words, if you’re logged into Wordpress, you’re also logged into ZenPhoto. This makes the user/password in the ZenPhoto config file meaningless. Here’s what you have to do to get this working: Read More…
Mozilla Extension Generator
Author einar | 01.08.2007 | Category code, extensions, javascript, mozilla, python
Since I started creating Mozilla extensions I spent a lot of time writing boilerplate code, and copying from one extension from the next. Then I found Ted Mielczarek’s Extension Generator which is a great page that takes some parameters and creates an extension ready for you to use. I used that for some time but in the end I still kept modifying each extension to fit my own style and include my library functions. So I decided to make my own Mozilla Extension Generator in Python Read More…
Javascript format strings
Author einar | 31.07.2007 | Category code, javascript
Python has been my favorite language for a while but since I started making Mozilla Extensions I’ve started to like Javascript a lot too. One thing I miss from Python though are the format strings. In Python you can always create a string like this:
s = '%s is a %s' % ('John', 'Moron')
Since Javascript is a very flexible language and allows you to alter its built in types I decided to try to create something similar for it. Here’s what I came up with:
Read More…
Pretty Wordpress Permalinks on IIS
Author einar | 30.07.2007 | Category code, meta, wordpress
I’ve been searching the web a bit for a way to make pretty permalinks work correctly on this site. The site is hosted on IIS so using mod_rewrite won’t work, and it’s on a shared server so the option of installing a mod_rewrite alternative for IIS won’t work either. I could get away with having almost pretty urls, with a index.php in them, like this: http://tech.einaregilsson.com/index.php/2007/07/30/pretty-wordpress-permalinks-on-iis/ but I didn’t like it.
The Using Permalinks section on the Wordpress page has a lot of info on this and it links to one solution that uses custom 404 pages to make this work but unfortunately I don’t think it’s a very good solution at all. What it does is parse the url from the 404 string, then re-implement all the rewrite url matching itself, make its own http request to the correct url, then write the data from that request into the response. It’s a good effort but it’s duplicating functionality already in Wordpress and making a new http request for every page hit which I don’t like. After searching around some more I found another 404 page solution that is very simple and elegant. All you have to do is create a 404 page and put the following 4 lines in it:
<?php
$qs = $_SERVER['QUERY_STRING'];
$_SERVER['REQUEST_URI'] = substr($qs, strpos($qs, ':80')+3);
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];
include('index.php');
?>
All this does is fix the REQUEST_URI and PATH_INFO variables and then include index.php, so Wordpress will do the rest. It’s simple, it doesn’t duplicate functionality already in Wordpress and it doesn’t have the overhead of another http request for every page hit. The installation steps are:
- Create the file wp-404-handler.php in your base Wordpress folder. (you can also download it here).
- Set your sites 404 page to point to the wp-404-handler.php url. Most control panels at web hosts allow you to do this. If you’ve got the option to select between FILE and URL then choose URL.
- Go to Options -> Permalinks in your Wordpress admin page, and choose an appropriate structure for your links. I chose Custom with this pattern:
/%year%/%monthnum%/%day%/%postname%/ - Enjoy!
Icelandic letters in Wordpress permalinks
Author einar | 27.07.2007 | Category code, wordpress
I use Wordpress for this site as well as my personal blog. It works very well with icelandic letters for the most part but there was one problem. When you create a new post and give it a title, the post slug is generated from the title. For example, the title of this post is ‘Icelandic letters in Wordpress permalinks’ and it’s automatically changed to ‘icelandic-letters-in-wordpress-permalinks’ in the url. When you have a post with special characters in the title they are either removed or changed to some ASCII equivalent. For instance, Á becomes A, Í becomes I, ö becomes o and so on. This worked well for all icelandic letters except three, they are þ, æ, ð. When I made a post with the title ‘Þátturinn’ the post-slug would become ‘þatturinn’ and when I tried to enter that address in my address bar it changed to ‘%c3%beatturinn’ and I got a ‘page not found’ error from Wordpress.
Now, you can manually enter the post-slug when you write a post, but I don’t wanna have to do that every time I post, so I dug around the Wordpress code and found the replacement function. It’s called remove_accents and is in the file wp-includes/formatting.php. There, right before the line ‘// Decompositions for Latin Extended-A’ I added the following code:
chr(195).chr(144) => 'D', chr(195).chr(176) => 'd',
chr(195).chr(158) => 'TH',chr(195).chr(190) => 'th',
chr(195).chr(134) => 'AE',chr(195).chr(166) => 'ae',
Now the characters are replaced automatically like this: Ð => D, ð => d, Þ => TH, þ => th, Æ => AE, æ => ae. I don’t know if everyone has this problem, or if it just has to do with the character set settings on my webhost but this works great for me. No more manually fixing page slugs! I’m gonna create a bug report with Wordpress and hopefully this will be accepted into the next version.
Few words in icelandic to help people find this post
: Íslenskir stafir í wordpress linkum post slug permalink permalinks
Update 02.08.2007: Just found out that there’s already a plugin that does the same thing, and it doesn’t require you to mess with your Wordpress files. You can get it at http://wordpress.is/saekja/ibaetur/iceslugs.tar .
Update 13.08.2007: I made a patch for this and submitted it to Wordpress. The changes should come in WP 2.3. The patch is on ticket #4739 .
Categories
- ASP.NET (1)
- C# (4)
- code (10)
- extensions (2)
- haloscan (1)
- javascript (2)
- meta (2)
- mozilla (2)
- msn (1)
- plugins (2)
- python (3)
- tips & tricks (3)
- utilities (1)
- Visual Studio (1)
- wordpress (5)
- zenphoto (2)