Swap Stereoscopic Image Parts

I wrote a silly bookmarklet for swapping the two halves of stereoscopic images on a web site—to turn normal stereoscopic images to cross-eyed-viewable images.

javascript: var i,im,ims = document.getElementsByTagName('img'),j=ims.length; for(i=0;i<j;++i){im=ims[i]; with(im.style){paddingTop=im.height+'px'; backgroundImage='url('+im.src+')'; backgroundPosition=(im.width/2)+'px 0%'; height='0px';}} void(0);

(Only tested in Chrome, but bound to work in a few other browsers.)

Posted in Computers en internet | Leave a comment

Parse strings as enum items

I wrote a helper function today that tries to parse strings as items of an enum. It’s very simple, but I think it’s beautiful. (Language: C#)

// Beautiful code
public static bool TryParseEnum<T>(string value, out T result) {
  if (Enum.IsDefined(typeof(T), value)) {
    result = (T)Enum.Parse(typeof(T), value);
    return true;
  result = default(T);
  return false;

// Simple enum
public enum Status {
  unknown, good, bad

// Testing code
public void Main(){
  Status one, two;
  if (TryParseEnum("good", out one))
    Response.Write(one); // writes "good"
  TryParseEnum("excellent", out two); // returns false
  Response.Write(two); // writes "unknown"
Posted in Computers en internet | Leave a comment

Embedding Flash in Google Wave

Oh hi! So you want to embed Flash in a Google Wave, huh? Well you can!
First add this HTML gadget via ‘add gadget via URL’: http://wave-ide.appspot.com/html.xml
Then, click ‘Edit’ on the gadget, and paste your embed code. Now click ‘view’ to see the code rendered. The Flash movie will be embedded in a crappy gray frame, but hey, you got embedded Flash in your Wave! Yay, right?
WRONG! Gray crap is crap! So, let’s add some javascript to remove the frame. Below your Flash embed code, paste the following script:

<script type=text/javascript>
var div = parent.document.getElementById('toolbarPane');
div.style.display = 'none';
div.parentNode.parentNode.style.backgroundColor = 'transparent';

And there you have it! Clean, borderless Flash in a Wave.
Posted in Geen categorie | 2 Comments

R2-D2’s scomp link arm interface totally changed positions

In the original trilogy, it was housed in the long right-most compartment on his front. See figure 1.
Figure 1 – R2-D2 with his scomp interface in The Empire Strikes back
However! In the new trilogy, it’s suddenly in a completely different compartment! Figure 2 shows that it is in the slightly smaller compartment left of his cooling vents.
Figure 2 – R2-D2 in Attack of the Clones. Note that the compartment the interface was housed in prior, is shown here; closed.
Posted in Geen categorie | 2 Comments

Converting CSV to KML for Google Maps, Revisited

Hi everybody! (Hi Dr. Nick!) I updated my post on converting CSV to KML! I now no longer replace silly characters ‘manually’. See the original post for details.
Oh, and the online CSV2KML convertor has been naturally been updated as well!
(Note: I made this post because the ‘CSV to KML’-post is by far the most popular content on this blog. I’d say +95% of the traffic gravitates towards that post. My post on Killer7 is the second most popular, because people sometimes google "Master, we’re in a tight spot".)
Posted in Geen categorie | 5 Comments

YouTube Visual Search Provider for Internet Explorer 8

Hi everybody! I recently made the jump to Internet Explorer 8 as my primary browser and discovered the joys of Visual Search Providers. Visual Search is just like regular search, but with suggestions as you type, where the suggestions can include images. Awesome.
One of the most obvious candidate websites for such a visual search is YouTube. However, I found that the official destination for IE8 Search Providers does not include one. So I made one myself!
To create a search provider, you need one xml file to define the provider, and one (dynamically generated) XML file that includes the search suggestions/results. How to create these XML files, can be found here.
In order to get dynamic suggestions from YouTube, I needed to get YouTube search results in XML format. As it turned out, this is very easy. You can find everything you need here.
So almost finished, right? Search provider is defined and we have search suggestions in XML. Wrong! The XML suggestions need to be in a specific format, of course (again, look here). So, I created a Python script that processes the XML YouTube search results and spits out visual search compatible suggestions.
Finally, I erected a Google App Engine app where my Python script will be hosted and ran. I inserted the URL to the GAE app in the search provider definition XML file, and presto! Visual YouTube results! Yay?
For those of you who want to do all this yourself, I will give you one tip: Unicode/UTF-8 conversions are a pain in the ass! Wait, that wasn’t a tip at all! I suck!
If you want to try the YouTube visual search I created (Internet Explorer 8 only! (I think)), paste the following in your browser bar, press enter, and click the button that magically appears:
javascript: document.write('<button onclick="window.external.AddSearchProvider(\'http://drop.io/download/public/lfbifcei8ahcv9fdapho/032c9e10d7973c48b3b994878bdcb630e0e45163/22c15b80-2f6f-012c-7cef-f0c403d9fbe0/23395630-2f6f-012c-0d4f-f79576abdabb/v2/content\')">Install Visual Youtube Search</button>');
If you want to observe the search provider definition file, look here. Remember that this is XML. I don’t know if you like that stuff! You might, though!
You can try the Google App Engine app here. This spits out generated XML. Do you like XML yet?
Posted in Computers en internet | Leave a comment

Deleting Songs on the fly from Windows Media Player

When listening to audio in Windows Media Player (at least 10 and 11), it doesn’t present you with an easy way to delete whatever you are listening to. I’ve come up with a convoluted solution to remedy this. Although convoluted, I find it suits my needs.
First, I created a new playlist in WMP (File > Create Playlist) which I named ‘Deletables’. Next, I created a Python script in the same folder as the playlist, which will read it and delete all audio files listed in there. Finally, I created a shortcut file with a key shortcut to execute this Python script (see this post for more on creating key shortcuts in Windows XP). The shortcut file’s target will look like this: "python scriptfile.py" (add paths where necessary, of course). Also, make sure the starting path corresponds with the location of the script and the Deletables playlist, or the script will try to access files in your user folder (Windows-quirk, I guess).
Now, whenever I’m listening to some audio files and I encounter something I want to delete, I just have to right-click the item in WMP’s ‘Play now’-list, and select ‘Add to… > Deletables’. By using the shortcut to execute the Python script, the file will be deleted. The file will not stop playing though, as it is still loaded in memory.
You don’t have to call the script every time after you add an item to Deletables. I myself only call it once a week or so, and then it will delete all the files added to Deletables since the last time the script was called. This also gives me some time to change my mind on a delete, if that may happen. To undo a future delete, simply open the Deletable playlist, and remove the files that have been given a second chance.
The Python code I used:

import os, re

f = open('Deletables.wpl')
l = f.readline()
a = ''
failed = ''

while l:
  b = re.findall('<media src="(.*?)"',l)
  if not b:
    a += l
    l = f.readline()
  file = b[0].replace('&apos;','\'')
  tfile = os.path.realpath(file)
  if os.path.isfile(tfile):
    failed += l.strip() + '\n'
  l = f.readline()


f = open('Deletables.wpl','w')

if failed:
  f = open('failedDeletes.txt','a')

Note: when the script is unable to delete a file (e.g. when the file was already deleted), it will write the location of said file to a text file, ‘failedDeletes.txt’. I find this useful, but if you do not, just remove the last four lines of code.

Posted in Geen categorie | Leave a comment