Skip to content

Instantly share code, notes, and snippets.

@Idorobots
Idorobots / gist:3865002
Created October 10, 2012 11:37
Memory Stats example
(require 'memory-stats)
(setq memory-usage-update-interval 5)
(setq memory-usage-format "Mem: %R Free: %F Swap: %S")
(memory-usage-start)
@Idorobots
Idorobots / gist:3864993
Created October 10, 2012 11:35
CPU stats example
(require 'cpu-stats)
(setq cpu-usage-update-interval 1)
(setq cpu-usage-format "Average: %A CPU0: %C0 CPU1: %C1")
(cpu-usage-start)
@Idorobots
Idorobots / gist:3379669
Created August 17, 2012 15:07
JSON part two
(grammar ((JValue < (/ String Number JObject JArray JTrue JFalse JNull)))
((JObject < (: "\\{") (? JPair (* (:",") JPair)) (:"\\}"))
`($(car JObject)
($(cons 'scope (cadr JObject)))))
((JPair < String (: ":") JValue)
`($(car JPair)
((var $(str->symbol (caadr JPair)) $(cadadr JPair)))))
((JArray < (:"\\[") (? JValue (* (:",") JValue)) (:"\\]"))
`($(car JArray)
($(vectorof (cadr JArray)))))
@Idorobots
Idorobots / gist:3379664
Created August 17, 2012 15:06
JSON grammar usage
(var json { "number": 1234.567,
"string": "abcd",
"object": { "member0": "value",
"member1": "value" },
"boolean": true,
"null": null })
(set! (json number) 9876.543)
@Idorobots
Idorobots / gist:3379336
Created August 17, 2012 14:44
ASM reader to PEG correspondence
sequence: (A B C ...) => A B C ...
ordered choice: (/ A B C ...) => A / B / C / ...
optional branch: (? ...) => (...)?
zero or more: (* ...) => (...)*
one or more: (+ ...) => (...)+
not: (! ...) => !(...)
and (lookahead): (& ...) => &(...)
drop node: (: ...) - Drops a node from the parse tree.
concat captures: (~ ...) - Concatenates captures.
@Idorobots
Idorobots / gist:3379103
Created August 17, 2012 14:25
Grammar extension
(syntax (Lambda < List (: "->") Expression)
`($(car Lambda)
((lambda $(caadr Lambda) $(cadadr Lambda)))))
(syntax (Expression < (/ Lambda String List Atom)))
(Expression "(map (x) -> (* x x)
(list 1 2 3 4 5))")
@Idorobots
Idorobots / gist:3378676
Created August 17, 2012 13:25
Simple Lisp grammar
(grammar ((Expression < (/ String List Atom)))
((String <- (:"\"") "[^\"]*" (: "\"")))
((List < (: "\\(") (* Expression) (: "\\)"))
`($(car List)
$(cdr List)))
((Atom <- (/ Number Symbol)))
((Number <- "[+\\-]?[0-9]+(\\.[0-9]*)?")
`($(car Number)
($(str->num (caadr Number)))))
((Symbol <- (! Number) "[^\\(\\)\"';\\s]+")
@Idorobots
Idorobots / gist:3358061
Created August 15, 2012 09:26
More fun with SICP
(var bus-size 16)
(var A (make-bus bus-size))
(var B (make-bus bus-size))
(var c (make-wire))
(probe 'Carry c)
(var S (make-bus bus-size))
(ripple-carry-adder A B S c)
(set-bus-value! A '(1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1))
@Idorobots
Idorobots / gist:3353115
Created August 14, 2012 21:18
Having fun with SICP
(var (a b s c) (times 4 make-wire))
(probe 'sum s)
(probe 'carry c)
(half-adder a b s c)
(set-signal! a 1)
(set-signal! b 1)
(propagate)
;; 0ns - sum: new value = 0
;; 0ns - carry: new value = 0
@Idorobots
Idorobots / gist:3312154
Created August 10, 2012 07:15
ASM code sample
#; ASM code sample**
#; Extend the language however you please.
(syntax (Ternary < Expression (: "\\?") Expression (: ":") Expression)
`($(car Ternary)
($(ternary-to-if (caadr Ternary)))))
#; Use the whole language to your advantage.
(function (ternary-to-if t)
`(if $(car t)