Skip to content

Instantly share code, notes, and snippets.

@sweemeng
sweemeng / output_hansard_english.xml
Created October 15, 2011 06:39
Hansard English Output in pseudoxml
<?xml version="1.0" encoding="UTF-8" ?>
<LTTextBox>MALAYSIA
</LTTextBox>
<LTTextBoxHorizontal>MALAYSIA
</LTTextBoxHorizontal>
<LTTextBox>DEWAN RAKYAT
</LTTextBox>
<LTTextBoxHorizontal>DEWAN RAKYAT
</LTTextBoxHorizontal>
<LTTextBox>ORDER PAPER
MALAYSIA
DEWAN RAKYAT
ATURAN URUSAN MESYUARAT
NASKHAH SAHIH/BAHASA MALAYSIA
http://www.parlimen.gov.my
@sweemeng
sweemeng / object2json.py
Created June 22, 2011 12:46
Output Objects To JSON
import json
"""
>>> c = C()
>>> c.a = 1
>>> c.b = 2
>>> c.__dict__
{'a':1,'b':2}
>>> c.to_json()
'{"a":1,"b":2}'
@sweemeng
sweemeng / sample.py
Created June 22, 2011 12:37
Example python objects
"""
>>> s = Sample()
>>> s.__dict__
{'test_val':1,'another_val':'a'}
>>> 'test_val' in s.__dict__
True
"""
class Sample:
def __init__(self):
self.test_val = 1
@sweemeng
sweemeng / gghc.c
Created April 2, 2011 15:39
Test integration of a few components for HSKL GGHC entry
#include <LCD4Bit_mod.h>
#include <EEPROM.h>
LCD4Bit_mod lcd = LCD4Bit_mod(2);
long randno;
int EEPROM_SIZE = 512;
int SIZE = 0;
void setup() {
pinMode(13, OUTPUT); //we'll use the debug LED to output a heartbeat
@sweemeng
sweemeng / command2pipe.sh
Created April 1, 2011 05:00
Convert all comma and windows newline to pipe,
sed "s/,/|/g" $1 > /tmp/pass1
tr "\r\n" "|" < /tmp/pass1 > $2
rm /tmp/pass1
@sweemeng
sweemeng / serial2eeprom.c
Created March 30, 2011 14:15
This is the proof of concept code for serial to eeprom
#include <EEPROM.h>
int EEPROM_SIZE = 512;
int incoming = 0;
char words;
int pos = 0;
int data;
void setup(){
Serial.begin(9600);
}
@sweemeng
sweemeng / gghc.c
Created March 28, 2011 12:53
implementation 0.001 of HSKL entry of Global Hackerspace Entry, btw it is untested
#include <LCD4Bit_mod.h>
#include <EEPROM.h>
//create object to control an LCD.
//number of lines in display=1
LCD4Bit_mod lcd = LCD4Bit_mod(2);
int adc_key_val[5] ={30, 150, 360, 535, 760 };
int NUM_KEYS = 5;
int adc_key_in;
@sweemeng
sweemeng / gghc.c
Created March 28, 2011 12:08
implementation 0 of Global Hackerspace Entry of HSKL
#include <LCD4Bit_mod.h>
//create object to control an LCD.
//number of lines in display=1
LCD4Bit_mod lcd = LCD4Bit_mod(2);
int adc_key_val[5] ={30, 150, 360, 535, 760 };
int NUM_KEYS = 5;
int adc_key_in;
int key=-1;
@sweemeng
sweemeng / gist:813177
Created February 6, 2011 06:05
show how to use python functools modules, partial
import functools
def adder(a,b,c):
return a+b+c
def adder2(a,b):
return a+b
add_three = functools.partial(adder,1,2)
add_one = functools.partial(adder2,1)