Skip to content

Instantly share code, notes, and snippets.

View mahmoud's full-sized avatar
Back on the grid!

Mahmoud Hashemi mahmoud

Back on the grid!
View GitHub Profile
@mahmoud
mahmoud / less.el
Created February 15, 2012 05:52
less major mode indentation
(defun less-css-calculate-indentation ()
"Return the column to which the current line should be indented."
(save-excursion
(end-of-line)
(let ((indent-level 0))
(while (not (bobp))
;; TODO search backwards
(backward-char)
(cond ((looking-at "{") (setq indent-level (+ 1 indent-level)))
((looking-at "}") (setq indent-level (- indent-level 1)))))
@mahmoud
mahmoud / datagen_out.txt
Created February 26, 2012 11:55
DataGen output
~/DataGen/src $ python main.py 20000 10 test
Lines: 20000, Files: 10, Base Name: test, Bucket: None, Prefix: None
[ 10%] Process #1 complete. (1.24 s) Hash: d41d8cd98f00b204e9800998ecf8427e
Compressed: 1699840 Uncompressed: 3592368 Ratio: 0.473
[ 20%] Process #2 complete. (1.25 s) Hash: d41d8cd98f00b204e9800998ecf8427e
Compressed: 1703936 Uncompressed: 3592484 Ratio: 0.474
[ 30%] Process #3 complete. (1.26 s) Hash: d41d8cd98f00b204e9800998ecf8427e
Compressed: 1699840 Uncompressed: 3592838 Ratio: 0.473
[ 40%] Process #4 complete. (1.26 s) Hash: d41d8cd98f00b204e9800998ecf8427e
Compressed: 1699840 Uncompressed: 3592434 Ratio: 0.473
@mahmoud
mahmoud / less_scope_test.less
Created March 2, 2012 10:02
less css scoping test
@test: 0;
.mixin() when (@test = 0) { background: blue !important; }
.mixin() when (@test = 1) { @test: 2; background: red !important; }
.mixin() when (@test = 2) { background: black !important; }
body {
@test: 1;
.mixin;
.mixin;
@mahmoud
mahmoud / greetings.js
Created March 25, 2012 22:43
brief closure demonstration
var greet = function(greeting) {
var full_greeting = greeting+', ';
var greet_name = function(name) {
console.log(full_greeting + name);
}
return greet_name;
}
var hello = greet('hello'); // builds a greeting function, prints nothing
hello('stephen'); // does the actual printing
@mahmoud
mahmoud / random_test.py
Created March 30, 2012 23:55
randomness detection (y'know, not really)
# test a supposedly random string (encrypted or hashed or something) for 50% 1s vs 0s
mypass = '\xf8\x16\x01-\xfd3\xf7\x06\xbf\xc4\x1eU=\xc0\xe8a\xf4\xa0\x8b\xd0'
x = ''.join(["{0:08b}".format(ord(a)) for a in mypass])
print x.count('0')/(len(x)+0.0)
@mahmoud
mahmoud / jsdom_memory.txt
Created April 9, 2012 01:36
jsdom memory problems
460 successful queries.
Memory stats:
{ rss: 250523648, heapTotal: 256133824, heapUsed: 226484224 }
940 successful queries.
Memory stats:
{ rss: 546824192, heapTotal: 533091840, heapUsed: 504648624 }
1340 successful queries.
Memory stats:
@mahmoud
mahmoud / gist:2348538
Created April 10, 2012 05:51
effing j. there's not even a syntax highlighter for it.
coli=: 4 : '({. x) i. < y' NB. {data w/header} coli {column name} => column index
col=: 4 : '}. (x coli y) {"1 x' NB. {data w/header} coli {column name} => boxed column data
colu=: 4 : '> x col y' NB. {data w/header} colu {column name} => unboxed column data
coln=: 4 : 'makenum x col y' NB. {data w/header} coli {column name} => numeric column data
colsel=: 4 : 'y , |: > x&col each y' NB. {data w/header} colsel {column name} [{column name} ...]
@mahmoud
mahmoud / gist:3045907
Created July 4, 2012 07:28
yappi profilin'
name #n tsub ttot tavg
..ut/asf/lib/gevent/hub.py.wait:381 126370 4.224324 0.000000 0.000000
../asf/lib/gevent/hub.py.switch:367 127794 1.108121 0.000000 0.000000
../asf/lib/gevent/hub.py.switch:581 126390 0.703636 1.496160 0.000012
..put/asf/lib/gevent/hub.py.get:607 126392 0.529035 0.000000 0.000000
..sf/lib/gevent/hub.py.__init__:545 126392 0.408749 0.546809 0.000004
..asf/lib/gevent/hub.py.get_hub:203 255211 0.309358 0.323718 0.000001
..asf/lib/gevent/socket.py.recv:379 141 0.308193 3.949099 0.028008
..t/asf/lib/gevent/ssl.py.close:347 162 0.070644 0.075873 0.000468
...6/json/decoder.py.JSONObject:162 420 0.063566 0.220138 0.000524
@mahmoud
mahmoud / pretty_print_xml.py
Created July 10, 2012 07:42 — forked from anonymous/gist:3079509
Pretty printing XML in Python
from StringIO import StringIO
import xml.etree.cElementTree as ET
def pretty_xml(xml_str, indent=" "):
"""
A very simple, hopefully not simplistic, XML pretty printer.
Concept courtesy Mark Williams.
"""
if not hasattr(xml_str, "read"): # ElementTree uses file-like objects
fn = StringIO(xml_str) # cStringIO doesn't support UTF-8
@mahmoud
mahmoud / pretty_print_xml.py
Created July 10, 2012 07:45
Pretty printing XML in Python
from StringIO import StringIO
import xml.etree.cElementTree as ET
def pretty_xml(xml_str, indent=" "):
"""
A very simple, hopefully not simplistic, XML pretty printer.
Concept courtesy Mark Williams.
"""
if not hasattr(xml_str, "read"): # ElementTree uses file-like objects
fn = StringIO(xml_str) # cStringIO doesn't support UTF-8