Python – pretty dictionary access for objects

June 28th, 2009

Instead of hash like access i.e. val = hash['key']

You can achieve a prettier val = obj.key :

class Obj:
..def add(self, k, v):
....self.__dict__[k] = v

o = Obj()
o.add(key, val)

Getting Actionscript 2.0 ComboxBox to work when using Loader component

February 3rd, 2009

If you’re using a and Flash Actionscript 2.0 Loader to import another .swf file to the stage and your ComboBox/dropdown is no longer working – all you need to do is import the ComboBox component to the library of the .fla file that contains the loader i.e. drag it to the stage then delete it.

It’s basically a bug though we’ll be polite and call it a quirk =)

Open source language reference

November 16th, 2008

Its a reference that shows how to do common operations in php, perl and python.

You can view it here.

Microsoft Word characters to ASCII

October 28th, 2008

Microsort Word uses some characters that are in the Windows-1252 character set in the range x80-x9F range that aren’t used in the Latin-1 (extended ASCII) character set that it’s derived from. Here’s a quick reference for converting them to an extended ASCII character set.

Written in python


conv = [
[u'\u2018',"'"], # 145 - \x91
[u'\u2019',"'"], # 146 - \x92
[u'\u201C','"'], # 147 - \x93
[u'\u201D','"'], # 148 - \x94
[u'\u2013',"-"], # 150 - \x96
[u'\u2014',"-"], # 151 - \x97
]

TSHML – two space html markup language

September 4th, 2008

I invented an extremely lightweight markup language which is used as a shorthand to author html documents. I wouldn’t be surprised if it’s been independently developed by several (million) other developers, but in case it hasn’t, you saw it here first! :) I called it TSHML – “two space html markup language”. It was inspired by coding in Python which uses whitespace in a similar fashion.

The rules are that one element is represented on one line, attributes can be optionally quoted in strings (double quotes are slash escaped) or not quoted (though they have to be if they contain spaces), childnodes are indented by two spaces, text nodes are created by specifying an attributes named “txt”.

He’s an example: – note i’ve substituted full-stops for spaces for the indent

div.id=myid
..p class=myclass style=”padding: 0px 10px 5px 5px”
….a href=http://emtek.net.nz txt=”Click \”your mouse\” here”
..p class=myclass
….span txt=”Or click ”
….a href=http://google.co.nz txt=”your mouse”
….span txt=” here”

If you use TSHML then you’ll need to write a program to convert it to something useful, probably XML.

PuTTY SSH Keep Alive with AutoHotKey

August 26th, 2008

If you are having trouble with PuTTY getting disconnected after being idle, usually being kicked by a router, try running this script with AutoHotKey:

; Optional – auto login script

run, …\putty.exe -load putty_profile , , , newpid
winwait, ahk_pid %newpid%
Send xxx.xxx.xxx.xxx{enter} ; put your IP here
sleep, 1500
ControlSend, , username{enter}, ahk_pid %newpid%
sleep, 500
ControlSend, , password{enter}, ahk_pid %newpid%

; KEEP ALIVE SCRIPT:
; %newpid% will refer to the original putty window, we need to refind the
; new shell window, which we do via ahk_class PuTTY
loop
{
sleep 60000
IfWinExist ahk_class PuTTY
{
IfWinNotActive ahk_class PuTTY
{
ControlSend , , date{enter}, ahk_class PuTTY
}
}
else
{
break
}
}

Remapping acer euro key

June 29th, 2008

(note this no longer works if you upgrade the bios — on my todo list to find out what the new char codes are)

My Acer 4250 came with rather annoyingly and pointlessly placed euro + dollar keys ‘inside’ the cursor key area.

Being a script monkey, I figured it would be rather useful to remap these keys to delete + backspace.

After much googling, the answer is to:

a) edit C:\Program Files\Launch Manager\MMKEYBD.CFG

comment out a couple of lines with “;” so that they look like this :

;Key 19 = 1,E0,33,E0,B3,F508,Euro Symbol
;Key 20 = 1,E0,34,E0,B4,F509,Dollar Symbol

this prevents acerware from hijacking these keys for its own purposes!

then download and install www.autohotkey.com

change the default script so that it reads

$SC133::Delete
$SC134::Backspace

add autohotkey to your startup folder, reboot and viola! remapped keys :)

Acer 4520 keyboard lag fix

June 29th, 2008

This is how you fix keyboard lag issue on the Acer Aspire 4520 Gemstone.

There are two separate ways that you can fix this issue:

The first fix is quite simple – disable the touchpad. Sorry touchpad users :( Press Fn-F7 to turn it off. Remember you can easily plug in a usb mouse instead, or if you’re the geeky type learn to navigate through windows using hotkeys.

The second fix is to upgrade the BIOS to the latest version. This isn’t anywhere as scary as it sounds.

You want the file FBIOS3630.zip, which you can find here

Unzip the contents and run the file SWinFlash.exe – and point it to the file Z03_3630.WPH

If you’re the highly paranoid type, then before you do this create a factory restore disc via the Acer empowering framework. However this is an official patch, so unless you’ve done something truly strange to your laptop, then there’s no reason why updating the BIOS shouldn’t work.

Don’t ask me how this one made it past Acer QA :/

Dreamweaver mx2004 code color CakePHP template files – .thtml .ctp

June 29th, 2008

You want to get dreamweaver to treat .thtml and .ctp files like php files. There are 2 config files that you’ll need to edit

View hidden file types

C:\Documents and Settings\[user]\Application Data\Macromedia\Dreamweaver MX 2004\Configuration\Extensions.txt

PHP,PHP3,PHP4,TPL,THTML,CTP:PHP Files

C:\Program Files\Macromedia\Dreamweaver MX 2004\Configuration\DocumentTypes\MMDocumentTypes.xml

<documenttype id=”PHP_MySQL” servermodel=”PHP MySQL” internaltype=”Dynamic” winfileextension=”php,php3,php4,thtml,ctp” macfileextension=”php,php3,php4,thtml,ctp” file=”Default.php” writebyteordermark=”false”>