Skip to content

Instantly share code, notes, and snippets.

@geoffrasb
geoffrasb / Object_toString_equal_expansion
Created December 20, 2011 13:30
Object::toString() and Object::equal(obj)
Object.prototype.toString = function() {
var key, result, val;
result = ["{"];
for (key in this) {
val = this[key];
result = result.concat(key, ":", val, ",");
}
result.pop();
return (result.concat("}")).join("");
};
genpair = (num)->
return [] if num<=1
result = []
for i in [0..num-2]
result = result.concat ([i,n] for n in [i+1..num-1])
return result
@geoffrasb
geoffrasb / gist:1791529
Created February 10, 2012 18:37
A graph expression grammar spec

A graph expression grammar spec

Tokens:

\s+			#ignore whitespace
{		"{"
}		"}"
[		"["
]		"]"
, ","
@geoffrasb
geoffrasb / gist:1951882
Created March 1, 2012 18:19
simple route
//114.34.230.1
//192.168.1.100
var http = require('http');
var fs = require('fs');
var url = require('url');
http.createServer(function (req, res) {
var pathname = url.parse(req.url).pathname;
console.log(pathname);
if(pathname=='/')
@geoffrasb
geoffrasb / gist:2157538
Created March 22, 2012 10:09
Hardware lab in lisp
(defun pin (atm)
(cond
((eql atm 'CA) 'P6);seg14 display
((eql atm 'CB) 'N4) ((eql atm 'CC) 'V5) ((eql atm 'CD) 'T5) ((eql atm 'CE) 'U7)
((eql atm 'CF) 'R3) ((eql atm 'CG1) 'N5) ((eql atm 'CG2) 'R5) ((eql atm 'CH) 'T3) ((eql atm 'CJ) 'T3)
((eql atm 'CK) 'V4) ((eql atm 'CL) 'V7) ((eql atm 'CM) 'R7) ((eql atm 'CN) 'T7) ((eql atm 'DP) 'U5)
((eql atm 'S1) 'N3);push button
((eql atm 'S2) 'P4) ((eql atm 'S3) 'P3) ((eql atm 'S4) 'L6) ((eql atm 'S5) 'M5)
((eql atm 'S6) 'U2) ((eql atm 'S7) 'U1) ((eql atm 'S8) 'T2)
((eql atm 'D1) 'K4);LED
@geoffrasb
geoffrasb / gist:2159403
Created March 22, 2012 16:32
self-lambda
#|
usage:
(funcall (self-lambda (n) (if (> n 0)
(self (- n 1))
n))
5)
|#
(defmacro self-lambda (param-lst &rest body)
(let ((fn (gensym)))
@geoffrasb
geoffrasb / mylib.lsp
Created May 5, 2012 09:33
my lisp lib
;longer,filter,group (p47
;flatten,prune (p49
;find2,before,after,duplicate,split-if (p50
;most,best,mostn (p52
;map0-n,map1-n,mapa-b,map->,mappend,mapcars,rmapcar (p54
;readlist,prompt,break-loop (p56
;mkstr,symb,reread,explode (p58
;memoize (p65
;rfind-if (p73
aaaaa
bbb
@geoffrasb
geoffrasb / gist:2828184
Created May 29, 2012 12:40
eval and macro
>(defmacro add-to-list (a lst)
`(setf ,lst (cons ,a ,lst)))
>(setf lst '(1 2)) ; lst是一個變數,值為(1 2)這個list
>(setf a 'lst) ; a是一個變數,值為#:LST這個symbol
>(cons 3 lst) ;lst先被evaluate
(3 1 2)
>lst
(1 2) ;lst的值不會變
(setf smdl
(quote
;-----------write SMDL here and command (compile-it "filename")----------------------------
;this is and example
(state-machine
(clock "clk")
(init-state A)
(triggerd
("tri"
"n_sig1" "n_sig2"))