Dream Machine

Here is a small application I wrote from pure boredom and curiosity.

What is it?

It is a pathetic attempt to simulate a dream machine. It is supposed to provoke hallucinations by stimulating the optical nerves with a specific frequency. That simulation can alter the brainwaves and make you see complex patterns of color behind your closed eyelids.
Did not work for me – might work for you.

Why?

I’ve read an article on this topic some time ago and got curious. I made this stupid application to give it a try.

I want more background on this!

Do you? Head over to http://en.wikipedia.org/wiki/Dreamachine

Download

right here

A word of warning

It might cause a epileptic seizure - so be careful if you have that kind of predisposition.

Skype crippling network performance

Another thing I've learned today: Whenever Skype runs in the "super-node" mode it will do some traffic shaping on your network.

While it does make sense for the limited DSL upstream one would have, it absolutely makes no sense to limit my 100 mbit link to the router down to ~90mbit. This would also cripple transfer from/to my NAS.

So, what can be done about that? You could try to setup some intelligent (desktop) firewall rules to prevent Skype doing NAT Traversal and becoming a Supernode. As we all know, Skype is VERY persistent when it comes to punching holes into your firewall. So this task might cost you some nerves and could potentially affect other applications you run on your desktop. So, what options do we else have? Apparently Skype does offer some hidden registry settings which will affect that behavior. Once you disabled the supernode feature using the registry snippet below your intranet network performance should return to its former glory

  1. Windows Registry Editor Version 5.00
  2. [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Skype]
  3. [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Skype\Phone]
  4. "DisableSupernode"=dword:00000001

Convert a RSS / Podcast Feed to a .pls Playlist

X-Mas time...
I just got my wife a nice WiFi Radio (yes, she does not give a sh** about this blog). She loves to listen to internet radio stations so it seemed like a cool gift. We'll know for sure in less than 4 days.

Anyway. I unwrapped it to make sure it works and to preinitialize it with some presets she likes. But wait! What about my presets? Yes, I love to listen to podcasts. While the device itself has some support for RSS feeds (browsing my genre, country etc.) - it won't allow adding a RSS feed to your favorites / bookmarks. Here it will only accept playlists.  

A minor inconvenience you can fix with some PHP and SimplePie. Here is a small script which will convert any arbitrary RSS Feed to a PLS ... well, playlist :)

  1. <?php
  2. require_once("simplepie.inc");
  3.  
  4. function getFeedItems($rss, $numberOfFeedItemsToFetch = 50)
  5. {
  6. $feed = new SimplePie($rss);
  7. $feed->init();
  8. $feed->handle_content_type();
  9. if ($feed->error()) die ($feed->error());
  10. return $feed->get_items(0,$numberOfFeedItemsToFetch);
  11. }
  12.  
  13. $url = urldecode($_GET["url"]);
  14. $numEntries= $_GET["numEntries"];
  15. if (!$numEntries) $numEntries=50;
  16. if (!$url) $url = "http://feeds.feedburner.com/cnet/buzzoutloud?tag=rtcol";
  17. $items = getFeedItems($url,$numEntries);
  18. $plsItems = array();
  19. foreach($items as $item)
  20. {
  21. if ($item->get_enclosure())
  22. {
  23. $plsEntry = array();
  24. $plsEntry["title"] = $item->get_title();
  25. $plsEntry["link"] = $item->get_enclosure()->link;
  26. $plsEntry["length"] = (int) $item->get_enclosure()->length;
  27. $plsItems[] = $plsEntry;
  28. }
  29. }
  30.  
  31. header('Content-type: audio/x-scpls; charset=utf-8');
  32. header('Content-Disposition: attachment; filename="playlist.pls"');
  33. ?>[playlist]
  34. NumberOfEntries=<?= count($plsItems) ?>
  35.  
  36. <?
  37. for ($i=0; $i<count($plsItems); $i++)
  38. {
  39. print("File".($i+1)."=".$plsItems[$i]["link"]."\n");
  40. print("Title".($i+1)."=".$plsItems[$i]["title"]."\n");
  41. if ($plsItems[$i]["length"] > 0) print("Length".($i+1)."=".$plsItems[$i]["length"]."\n");
  42. else print("Length".($i+1)."=-1\n");
  43. print("\n");
  44. }
  45. print("version=2");
  46. ?>

The usage is quite simple. Call the script like this:

http://myserver/the_script.php?url=[encoded rss url]&numEntries=[optional: max number of entries in the pls]

If you don't know how to encode a URL properly, try this:

  • open a new tab in firefox
  • enter
    javascript:document.write(escape("http://your.friggin.url/feed.xml"))
    into the address bar
  • copy & paste the result

If the Feed-URL does not contain any parameters (chars such as &, ? or =) you probably won't need to encode it. Won't hurt though!

You also might want to add a fake URL part (path info) if your client needs that .pls ending in the url. so the script-call would be like:

http://myserver/the_script.php/fake.pls?url=...&numEntries=...

Oh! And you will need a copy of SimplePie for the script to work. Grab it over here

download the script bundled with SimplePie

Ummm... WHAT!?

Webstart ErrorWebstart ErrorTranslates to "Entryscreen: Error rcv". Yes... I have NO IDEA.

Unexpected Consequences


Ooops! That was quite unexpected

Accessing Arrays in .NET/c# via Reflection

Yesterday I was implementing a generic serializer (for logging purposes). While there is a good number of XML serializers available for .NET - none of them was meant to be used for only the purpose of reading. That means, I would not need deserialization but only some nice human readable output.

Anyway, thats not the point here. What took me about an hour to figure out is how to handle arrays (of natives) via reflection. I kinda feel stupid, but let me show you what i tired:

  1. Object propertyValue = prop.GetValue(o, null);
  2. if (propertyValue != null &amp;&amp; propertyValue.GetType().IsArray)
  3. {
  4. //if you need the type, here is how we get it, it's not used
  5. //in this example.
  6. Type arrayType = propertyValue.GetType().GetElementType();
  7. object[] arr = propertyValue as object[];
  8. for (int i = 0; i &lt; arr.Length; i++)
  9. {
  10. // serialization logic goes here
  11. }
  12. }
  13. ...

While this might work perfectly for arrays of "real" objects such as string[] - it will fail when your array is composed of native objects such as long[]. The cast to object[] will get you a nice null reference. Yummy.

After that I've been looking for Array.ForEach() which was pretty interesting, but did not really help due to it's generic nature. The solution was much simpler in the end, it just did not cross my mind to cast the propertyValue to Array - sometimes .NET can be pretty mysterious in terms of Autoboxing. Here is how it should be done:

  1. Object propertyValue = prop.GetValue(o, null);
  2. if (propertyValue != null &amp;&amp; propertyValue.GetType().IsArray)
  3. {
  4. Array array = propertyValue as Array;
  5. foreach (var arrElement in array)
  6. {
  7. // serialization logic goes here
  8. }
  9. }
  10. ...

Straight forward, simple - makes me feel stupid.

TWiki Installation / Collaboration Software?

I've been looking into collaboration solutions for small teams recently. TWiki (.org) caught my attention so I decided to give it a try. Jeez! I am used to difficult installations (can you spell J2EE?), but what TWiki expects me to do is way beyond the "userfriendly" term.

You have to create/validate 3 .htaccess files, add pretty lengthy configuration files to your apache vhost config, beat the crap out of file permissions - all of this only to get confronted with a setup screen basically telling you to check every option once again since this is "what it guessed".

It is not about rocket science, no magic involved here either. But considering the time spent on the installation I had also to consider the time I will be spending on maintenance and security updates. Seems really like a nice piece of software, but given those facts? Got kicked out faster than it was installed.

Bummer.

Any recommendations on collaboration software? I've been eyeing on Clearspace and Confluence, but none of them offers a solution for VERY small teams for a reasonable price (preferably free). Oh, and I don't mix it up with groupware which is more appointment / mail centric.

man more less

this falls into the category: things I've learned today.

Yes, the headline might be looking pretty funny. Let's presume you are reading man pages and notice "--MORE--" at the bottom of your screen. Ouch.. no paging or searching in the manpage. No problem, let's google then for "man more less" ... or maybe not - this won't give you any useful help on replacing the more manpage pager with less. 

To sum it up: set your PAGER environment variable to "less" - there goes another annoyance you won't have to worry about ever again.

Project Euler

So, you want to give your programming skills some training? Or just want to get familiar with a programming language and all test-projects you can come up with are pretty large and have been done 1000 times before? Yes, I know, your blogging software will be badass but will it be ever ready?

Anyway, If you are looking for some nice exercises which will also improve your math skills dramatically - head over to Project Euler and practice!

It contains a lot of math problems which can only be solved using a computer and won't knock out you right away, the challenges will guide you through ascending difficulty levels and should always give you an idea about the math you should use. 

Huh!? Happy Birthday!

To Me!

Well... maybe not exactly - I've just noticed that it has been exactly one year since I installed drupal on this machine.

Cheers!

Syndicate content