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';
</script>

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.
 
Amazing!
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()
    continue
  file = b[0].replace('&apos;','\'')
  tfile = os.path.realpath(file)
  if os.path.isfile(tfile):
    os.remove(tfile)
  else:
    failed += l.strip() + '\n'
  l = f.readline()

f.close()

f = open('Deletables.wpl','w')
f.write(a)
f.close()

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

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

Key Shortcuts in Windows XP

Key shortcuts in Windows XP frustrate me. For one thing, you can only assign key shortcuts to shortcut files (.lnk files) on the desktop. At least, that’s the consensus. It’s not completely true, though. You can also assign ‘certain’ key combination shortcuts to the shortcut files found in Programs > Accessories. The caveat is that the key combination must be of the form ‘ctrl + alt + …’, whereas shortcuts on the desktop can also be given key combinations with ‘ctrl + shift’.
So, not a perfect alternative to having a dedicated shortcut file on the desktop, but it could help you declutter a little.
To assign a key combination to a shortcut file, open the files Properties menu by right-clicking on it and choosing ‘Properties’, or press Alt+Enter when the file is selected. Now select the ‘Shortcut’ entry field, and press the keys you would like to use. Finally click Ok, and you’re all set.
Posted in Geen categorie | Leave a comment

Fullscreen with task bar

I like maximizing screen estate just as much as the next guy, but some things are just useful to have on-screen at all time. Like the Windows Task Bar for example. Most fullscreen-modes of software hide the task bar, however. This might be preferred sometimes, but when it’s not, change it!
The following C++ code uses the Windows API (formerly win32 API) to change the size of an Internet Explorer window (which will reveal the task bar when the window was in fullscreen-mode).

#include <stdio.h>
#include <Windows.h>
int WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
   HWND lHwnd = FindWindow("IEFrame", NULL);
   MoveWindow(lHwnd,0,0,1280,770,TRUE);
   return 0;
}

Above code is quite crude, as the window name and desired window size are hard-coded in. ‘IEFrame’ is the name of an IE7 window (probably works for older/newer versions as well). My monitor’s resolution is 1280 × 800 and the task bar is 30 pixels high, which leads to the 1280 and 770 parameters.
If you want to change the code to target other programs, you’ll need to do some Googling for yourself (if you ask nicely in the comments, I might do it for you!). Remember that you need the Windows API (comes with the Microsoft Platform SDK) to compile, though.
 
A compiled version of the code above can be downloaded from here.
Posted in Computers en internet | Leave a comment

Yea vs. nay, yay vs. boo

 
‘Yea’ is a very old-fashioned formal way of saying ‘yes’, used mainly in voting. It’s the opposite of—and rhymes with—’nay’. When you want to write the common casual version of ‘yes’, the correct spelling is ‘yeah’ (sounds like ‘yeh’).
[Examples of yay:] When the third grade teacher announced a class trip to the zoo, we all yelled ‘yay!’ (the opposite of ‘boo’!). That was back when I was only yay high.
from Common Errors in English.

 
No way! Learn something everyday, eh?
Posted in Geen categorie | Leave a comment