January 27, 2012

Getting pyglet setup in OS X 10.7.2


  1. Create a virtual env and activate it
  2. hg clone https://code.google.com/p/pyglet/
  3. pushd pyglet; python setup.py install
  4. popd
  5. easy_install  pyobjc==2.3 # the ==2.3 is required as of 2012-01-27, or pyobjc-core will not install
  6. python -c "import pyglet" # this step should not fail 


Cheers,
Steve

August 23, 2011

Manchester encoding/decoding in LibHiJack


The hijack iPhone library implements Manchester encoding for digital communication.  Manchester encoding maps 0 to high-low transition, and 1 to low-high transition.

The iPhone library generates the transitions using full or half period of a sine wave, using a full period when a bit run is detected. An example of this is shown below.

Manchester encoding of 0110011101 by libHiJack


Detection of Manchester encoding is relatively simple: first the signal is regenerated into a square wave by setting all values above 0 to 1 and 0 otherwise. The number of samples between transitions (0 to 1 or 1 to 0) is then measured. When this interval is within an acceptable range (as determined by the baud rate) the bit is read simply by taking the value of the regenerated square wave immediately after the transition. This works out nicely because 1 maps to a low-high transition, and the value immediately after transition is 1, while 0 maps to high-low transition, and the value immediately after transition is 0.

The important thing to note is that detection of a bit occurs at the transition from one bit to the next, and the code ignores transitions during a bit period. Specifically a transition must occur between 3/4 and 3/2 bit periods from last bit detection, otherwise it is ignored.

For example the transition between sample 64 and 96 is ignored because it occurs 1/2 a bit period since the last bit detection at sample 64.

Finally, the UART frame used consists of a start bit, eight data bits, one parity bits and one stop bit. Note my example doesn't include the parity bit since I reimplemented the encoding algorithm in python to produce the graph.

Cheers,
Steve

August 02, 2011

Brendanites of the Brendanverse

Of all Brendanites, the worst off are the criminals and other malcontents. Water-boarding is par-for-course as is other cruel and unusual punishments, like electric-clamps-on-nipples and listening to boy bands non-stop. By the O'Neill doctrine, if it worked before then whatever it is is OK now and forever. Amen.


While criminals have it bad in Brendanverse, the entrepreneurs have it easy. Starting business in Brendanverse is simple: find a market and setup shop. No need to worry about established competition, they won't do things like undercut your prices or bad mouth you in front of their customers. No siree, that's not how Brendanverse works. 

You see, in Brendanverse a company that owns, say 70% of the market, will do nothing like leverage their market share and resources to drive out, hinder or crush their competitors. In fact, calling them competitors is a misnomer: it implies competition and we can't have that. Companies are more like friends, happily coexisting and sharing their toys, aka customers.

Even more blessed than the entrepreneurs are the Chosen - the Journalists (not the Jews). They have all the right the Government has, including and not limited to reading people's emails and tapping their phones. These are rights that, by the O'Neil Doctrine, the Government owes to journalist, because unlike the Government, a Journalist is the epitome of integrity and honesty. They rise above the law and accountability and other trifling matters like FOI requests.


Whoever they are though, every Brendanite is a completely rational human being unswayed by emotional rhetorics, who gives every opinion their due weight before making a decision.

What a brave new world, with such people in it.

--

Having had a glimpse of the mind of Brendan O'Neil, I can't help but think he is someone who when confronted with an uncomfortable question latches on to the nearest superficial answer and runs with it.

Some people call him a "passionate defender of free speech" which brings to mind the following quote by Jascha Heifetz:

“No matter what side of an argument you're on, you always find some people on your side that wish you were on the other side.”

I wonder if he supports the right of people to yell fire in theatres...

Cheers,
Steve



June 06, 2011

MYOB Not Printing Chinese Characters in Invoices

Simply set the language for non-unicode programs to Chinese (PRC) and it will magically work.



Cheers,
Steve

May 29, 2011

git with multiple svn-remotes

Use git init to create an empty git repository, then edit .git/config to add the svn remotes:

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[svn-remote "svn"]
url = file:///home/steve/code/svn-repos/foo
fetch = trunk:refs/remotes/trunk
branches = branches/*:refs/remotes/*
tags = tags/*:refs/remotes/tags/*
[svn-remote "svn-other"]
url = file:///home/steve/tmp/foo-svn-other
fetch = trunk:refs/remotes/svn-other/trunk
branches = branches/*:refs/remotes/svn-other/*
tags = tags/*:refs/remotes/svn-other/tags/*

It is assumed at this point svn-other is simply a copy of svn. They are allowed to diverge later.

Do a git svn fetch -R svn to initialise git svn. To manage commits between the two svn remotes, create local tracking branches of remote branches:

$ git checkout -b trunk-other remotes/svn-other/trunk

I ended up with something like :

  master
  trunk
* trunk-other
  remotes/svn-other/trunk
  remotes/trunk

You can pull changes from one svn repository then push it to another:

$ git svn fetch -R svn
r1 = 049fed636e283096986e0eefa261be0525d8d7b3 (refs/remotes/trunk)
Checked out HEAD:
$ git svn dcommit
Committing to file:///home/steve/tmp/foo-svn-other/trunk ...
A test
Committed r2
A test
r2 = 10613af6701eca4b30a3ff89ab408e38ca157fa0 (refs/remotes/svn-other/trunk)
No changes between current HEAD and refs/remotes/svn-other/trunk
Resetting to the latest refs/remotes/svn-other/trunk

Cheers,
Steve

May 18, 2011

Find and svn add all untracked files

svn st | grep '^?' | sed 's/^[? ]*/"/' | sed 's/$/"/' | xargs svn add

Cheers,
Steve

May 08, 2011

Firehol and mDNS


Here is my firehol.conf that allows multicast mDNS packets through:


# define mdns so we will accept it
server_mdns_ports="udp/5353"
client_mdns_ports="5353"


interface eth+ multi
   policy return
   server mdns accept
   server multicast accept                                                                                                        


interface eth+ home src "${home_ips}"
    server  all         accept
    client  all         accept


Initially I had the server mdns accept and server multicast accept inside the home interface, but this didn't work. Firehol's developer, Mr Costa Tsaousis, pointed out that src "${home_ips}" on home would exclude broadcast packets sent from MAC addresses, thus the second interface definition (multi).

Cheers,
Steve

May 07, 2011

Success for Science

Just finished packaging my engineering thesis project into a more portable format: an altoids tin! I have seen people put some neat stuff inside them, and I am chuffed I managed to as well :) Though I had to cut through the lid for the display. And I only had to use the hacksaw once.



Cheers,
Steve

May 06, 2011

Improved the DSO Nano Probes

Got parts from element14 today: hook probes and right-angle 3.5mm mono plug. Modded my DSO nano probes, replacing the micro-tweezer probes and the connector. Interestingly the factory probed using a stereo connector, but the mono replacement works just as well.


This along with BenF 3.61a firmware upgrade has improved the DSO nano somewhere between 100 to 1000 times.

Cheers,
Steve

April 23, 2011

My Err99 Resolution

Err99 is a somwhat common error encountered by Canon DSLR users. Because it is something of a catch-all error code a variety of causes and resolutions can be found via google. In my case the error was fixed by a firmware upgrade while it was in the hands of Canon camera servicing personnel, so if you find you have exhausted all options, send it back to Canon!
For what it is worth, the Camera already had what I thought was the latest firmware, perhaps I downloaded the wrong version, or Canon worked some additional magic.


Cheers,
Steve

Another Galaxy Down

Found NGC 4594, aka the Sombrero Galaxy.


In addition also found what is probably cataracts in my eyes >.<


Cheers,

Steve

April 18, 2011

TIL: const, NSError, NSApplicationsupportDirectory


  • const char *foo; is not the same as char * const foo; The former declares a pointer to constant char, while the latter declares a constant pointer to char.
  • - [NSError localizedDescription] returns the object for key NSLocalizedDescriptionKey in the error's userInfo dictionary. I always wondered how to set it since there is no setLocalizedDescription:.
  • On iOS the application's Application Support directory doesn't seem to exist by default, unlike the Documents directory. This has to be created programmatically.

Cheers,
Steve