My pretty face [ László Monda's Blog ]
Exploring the cyberspace, one quadrant at a time!

Archive for April, 2011

TechnoStar UH1000 USB hub disassembly

Monday, April 25th, 2011

This hub is a cheap one, featuring the venerable GL850G which is used by pretty much almost every USB 2.0 hubs on Planet Earth.

<object width="500" height="375"><param name="flashvars" value="offsite=true&#038;lang=en-us&#038;page_show_url=%2Fphotos%2Fmondalaci%2Fsets%2F72157626453399477%2Fshow%2F&#038;page_show_back_url=%2Fphotos%2Fmondalaci%2Fsets%2F72157626453399477%2F&#038;set_id=72157626453399477&#038;jump_to="></param><param name="movie" value="http://www.flickr.com/apps/slideshow/show.swf?v=71649"></param><param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/slideshow/show.swf?v=71649" allowFullScreen="true" flashvars="offsite=true&#038;lang=en-us&#038;page_show_url=%2Fphotos%2Fmondalaci%2Fsets%2F72157626453399477%2Fshow%2F&#038;page_show_back_url=%2Fphotos%2Fmondalaci%2Fsets%2F72157626453399477%2F&#038;set_id=72157626453399477&#038;jump_to=" width="500" height="375"></embed></object>

Speedlink SL-8850-SBK VIGO USB soundcard disassembly

Monday, April 25th, 2011

This device is driven by CM108 High Integrated USB Audio I/O Controller. Apart from that IC it has only a handful of components like the two audio jacks, the USB plug, the crystal, a couple of capacitors and some resistors. The device shows up as "C-Media USB Headphone Set" because no external EEPROM is used for custom configuration.

<object width="500" height="375"><param name="flashvars" value="offsite=true&#038;lang=en-us&#038;page_show_url=%2Fphotos%2Fmondalaci%2Fsets%2F72157626437169353%2Fshow%2F&#038;page_show_back_url=%2Fphotos%2Fmondalaci%2Fsets%2F72157626437169353%2F&#038;set_id=72157626437169353&#038;jump_to="></param><param name="movie" value="http://www.flickr.com/apps/slideshow/show.swf?v=71649"></param><param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/slideshow/show.swf?v=71649" allowFullScreen="true" flashvars="offsite=true&#038;lang=en-us&#038;page_show_url=%2Fphotos%2Fmondalaci%2Fsets%2F72157626437169353%2Fshow%2F&#038;page_show_back_url=%2Fphotos%2Fmondalaci%2Fsets%2F72157626437169353%2F&#038;set_id=72157626437169353&#038;jump_to=" width="500" height="375"></embed></object>

Ultimate Flash XHTMLizer 0.1 released

Sunday, April 24th, 2011

Ultimate Flash XMTMLizer is a WordPress plugin that turns Flash embed code into well-formed XHTML by escaping object tags on the server side and unescaping them on the client side using JavaScript.

Tabs vs Spaces

Sunday, April 24th, 2011

Ok, this is some serious shit that drives me crazy. The reason why you should never, and I mean never and let me emphasize NEVER in your entire life use tabs for indentation is because:

  • We use spaces in the code to separate words anyways.  Why do you wanna introduce yet another character?
  • Tabs will be displayed differently depending on the editor in question.
  • People are gonna mix tabs and spaces in surprisingly novel (or just plain random) ways which will screw indentation even more than before because it's harder for editors to figure out the correct indentation in this case.
  • The mixture of tabs and spaces will produce lots of redundant lines in your {SVN / Git / whatever VCS} diffs because developers will (un)intentionally change them which is gonna be a lot of fun during code reviews.
  • Tabs are evil!  They're evil, evil, evil!  Don't use 'em! (Except for Makefiles (which as you may suspect are EVIL!))

As a last word, it's not possible to avoid using spaces for indentation in such scenarios:

<tab><tab><tab>function_call(arg1, arg2, arg3,
<tab><tab><tab>              arg4, arg5, arg6);

Long life to spaces!

dumbsvnreview 0.3 released

Sunday, April 24th, 2011

Check the changelog and the actual release.

Ethernet cable labelling

Thursday, April 21st, 2011

Ever felt that you have too many cables in your home and don't know which one leads where?  Welcome to my world!  Here's my recipe to how to make the situation easier.

It all starts with a sticky tape.

IMG_1192

Now comes the pen.

IMG_1194

Let's cut the tape with scissors.

IMG_1196

At this point you should remove the protective foil from the back of the tape to expose the glue and shape a loop.

IMG_1197

As a final move, pull the cable through the loop and push the tape against the cable to make it stick.

IMG_1199

When doing all the above properly, you'll get a of sight that makes the pants of any nerd wet.

 

Make your OpenWrt router automatically enable your home server and notify you

Thursday, April 14th, 2011

Here's the situation: I have a Mini-ITX home server in my LAN that sometimes gets disabled when the power goes down. I could setup its BIOS to get automatically enabled when it gets power but considering the nature of power outages it may happen that the power goes out and on in rapid succession over a short amount of time which isn't really good for the hardware.

I'd rather choose my server to be checked on a 5 minute basis and have it automatically woken up and I also wanna be notified by email on such an occasion so that I can SSH into it and uncrypt the crypto partition.

I'm about to carry out this task using my OpenWrt driven router. Everything is pretty straightforward, except that I can't send emails through GMail SMTP using Openwrt because mini_sendmail lacks SASL support so I'll just fetch a PHP script that'll actually send the mail.

openwrt:/usr/bin/supervise-host

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/sh
 
if [ $# -ne 2 ]; then
    echo "Usage: $0 HOSTNAME NOTIFICATION-SCRIPT-URL"
    echo "Ping HOSTNAME and if it's down then WOL it and send a notification mail to the admin."
    echo "NOTIFICATION-SCRIPT-URL?host=HOSTNAME will be fetched to send the actual mail."
    echo "Example: $0 mybox http://mydomain.com/notifyme.php"
    exit
fi
 
watched_host=$1
notification_script_url=$2
 
watched_host_down_file=/tmp/$watched_host.down
 
ping -c 1 -W 1 $watched_host > /dev/null
is_watched_host_alive=$?
if [ $is_watched_host_alive -eq 0 ]; then
    if [ -e $watched_host_down_file ]; then
        echo "$watched_host has been woken up"
        rm -f $watched_host_down_file
        wget $notification_script_url?host=$watched_host
    fi
else
    echo "waking up $watched_host"
    touch $watched_host_down_file
    wol $watched_host
fi

Be aware that the above wol utility is a home-cooked one.

openwrt:/etc/crontab/root

0
1
# m h  dom mon dow   command
0,5,10,15,20,25,30,35,40,45,50,55 * * * * supervise-host mybox http://mydomain.com/notifyme.php

At this ponit restart cron on OpenWrt.

mydomain.com:/var/www/notifyme.php

0
1
2
< ?php
mail('admin@mydomain.com', $_GET['host'] . ' has been rebooted', 'uncrypt me!');
?>

Enjoy!

Detecting primary language in PHP by HTTP Accept-Language

Wednesday, April 13th, 2011

There you go:

0
1
2
3
4
5
6
7
8
9
$accepted_languages = explode(';', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
$primary_language = $accepted_languages[0];
if ($pos=strpos($primary_language, ';') !== false) {
    $primary_language = substr($primary_language, 0, $pos+1);  // Throw away quality value.
}
if ($pos=strpos($primary_language, '-') !== false) {
    $primary_language = substr($primary_language, 0, $pos+1);  // Throw away dialect.
}
 
header("Location: http://mysite.com/$primary_language"));