18th October 2019

Let's implement zlib.decompress()

Ever wondered how lossless compression in PNG files, ZIP files is achieved? In this article, we will attempt to gain some insight into it by writing a decompressor for the zlib format, which PNG and ZIP files use for compression!

Read more...



7th October 2019

WebGL experiment: infinite plane

Started off as an experiment on animated raycasted skydomes with moving textures, but then evolved into examining how one could render an infinite plane with z-culling and without using gl_FragDepth (as it's not supported in GLES2).


20th September 2019

Encoding x86-64 instructions: some worked examples

To perform its compile-time evaluation duties CIR includes an x86-64 JIT. Unfortunately, when I looked around I couldn't find a ready-to-use C assembler library (there's one for C++ though), so I had to clobber together my own. While many websites explain how to do the encoding for some simple instructions, few would teach you how to encode any x86-64 instruction. With this post I hope to bridge the gap by showing, though some worked examples, my experience of encoding x86-64 instructions using information from an x86 instruction encoding reference such as http://ref.x86asm.net/index.html.

Read more...


31st August 2019

A Javascript DSL for WASM-JS bindings

bpat is a cross-platform portability layer for multimedia applications that I am currently developing. It can run on web browsers via WebAssembly (WASM). However, WebAssembly alone can't access the Web Platform APIs needed for multimedia applications such as WebGL and WebAudio. Instead, it can only do so by calling Javascript functions which would then call the Web platform APIs.

In this post, I'll talk a bit about the Javascript-like DSL developed to make writing WASM-to-JS bindings a pleasant experience in bpat. This DSL allows developers to write Javascript modules which can selectively export functions to WASM and import functions from WASM.

An example Javascript module written in the DSL is:

import { getValueFromWasm } from '@wasm-exports';
import { console } from '@js-globals';

export("wasm") function printValueToConsole() {
  console.log(getValueFromWasm());
}

Read more...



3rd August 2019

UDML: A minimal sexp-like document markup language

UDML in action

UDML (Unnamed Document Markup Language) is a minimal document markup language that I created for this website. An example document is:

{\h1 A h1 header}

Paragraphs are separated by a blank line.

2nd paragraph. {\i Italic}, {\b bold} and {\tt monospace}.
Here is a link to {\href http://example.com/ a website}.

{\* this is}
{\* an}
{\* itemized list}

{\h2 A h2 header}

{\. This is}
{\. a numbered}
{\. list}

In this post I'll describe the background and my thought processes behind the design of this markup language.

Read more...


4th January 2012

"Stupid Mode" in wvdial

As shown in my previous post, I could use my Blackberry's 3G connection to connect to the Internet over bluetooth. However, there was a problem. Everytime I used wvdial to connect to the internet, wvdial would pause for a long while, then print:

Don't know what to do! Starting pppd and hoping for the best.

before starting pppd and connecting to the Internet.

This was troublesome because I suspend the EeePC often, and everytime I wake it up from sleep I would have to wait a long while before internet access would be available.

Thankfully, one additional line in wvdial.conf fixed this:

Stupid Mode = 1

And the problem was solved since wvdial would start pppd immediately once it connected to the ISP. Problem solved -- by making wvdial stupid.


31st December 2011

3G Internet over bluetooth on Asus EeePC 1000H

Since the holidays started, I have been trying to get all the computers up-to-speed, running software updates and reformats, since I'm pretty sure that there will be no time for me to bother with malfunctioning computers next year.

I put my eeepc 1000 back into action recently (fixing its broken keyboard due to its vulnerability to water), and that led me to wonder whether the Blackberry actually supports internet thetering, especially since there is no such thing mentioned in its user interfaces. Apparently it can - over bluetooth and USB. Linux dosen't seem to detect anything special when I plugged it in via USB - perhaps extra drivers are needed. Bluetooth works though, so I'm going with that.

For some weird reason, eeepc has 2 rfkill switches for bluetooth. One is definitely located at /sys/class/rfkill/rfkill1, and the other, which will only appear once rfkill1 is turned on, will have a random number:

% ls /sys/class/rfkill
rfkill0  rfkill1
% sudo zsh -c 'echo 1 > /sys/class/rfkill/rfkill1'
% ls /sys/class/rfkill
rfkill0  rfkill1  rfkill2
% sudo zsh -c 'echo 1 > /sys/class/rfkill/rfkill2'

After installing bluez, I then started the bluetooth daemon:

sudo /etc/rc.d/bluetooth start

The hci0 device also needs to be brought up or hcitool won't detect it:

sudo hciconfig hci0 up

I then had to allow my Blackberry to be discoverable by bluetooth, then I scanned for devices using:

% hcitool scan
Scanning ...
    XX:XX:XX:XX:XX:XX  pykblackberry

Which allows me to find the device ID XX:XX:XX:XX:XX:XX.

I then had to pair the device using:

sudo bluez-simple-agent

Then connecting to the eeepc through the blackberry. This only needs to be done once.

Then the blackberry had to be binded to a rfcomm device. I had no way of guessing which channel blackberry uses for modem (No idea where to find spdtool, any ideas?), so I just guessed 1:

sudo rfcomm bind 0 XX:XX:XX:XX:XX:XX 1

Once binded, the /dev/rfcomm0 device will be available. I then just had to configure wvdial to use it. My wvdial config at /etc/wvdial.conf (I'm using Singtel):

[Dialer Defaults]
Init4 = AT+CGDCONT=1,"IP","internet"
Modem Type = Analog Modem
Phone = *99#
ISDN = 0
Username = 65ideas
Init1 = ATZ
Password = internet
Modem = /dev/rfcomm0
Baud = 460800

Then to connect:

sudo wvdial

Seems like quite a lot of effort though. I'll probably code up a script which can be activated with a button or something.


29th December 2011

Mail bots (Part 1)

Recently I have taken a liking to mail bots -- programs which send out notifications and receives commands via email. I can receive notifications about all the background processes running in the servers I have to manage, and I can then respond to these notifications naturally via email. Very convenient because I can use email on the go via my handphone.

I'm aiming to make it easy to script and install mail bots on my servers. This comes in two steps -- first part is about configuring the SMTP server to execute programs when emails are sent to a certain email address, and the next part is coding the programs which will execute to take action based on the contents of the message. This post series will detail my efforts in getting all of this to work.

Read more...