Skip to content

Instantly share code, notes, and snippets.

function deepMap(obj, fn, that) {
var stack = {0: {obj: obj}},
sp = 0,
ss = 1,
scope, keys, i, val;
while ((scope = stack[sp++])) {
keys = Object.keys(scope.obj);
for (i = 0; i < keys.length; i++) {
val = scope.obj[keys[i]];
fn.call(that, val, keys[i]);
var TrueXMLHttpRequest = XMLHttpRequest;
XMLHttpRequest = function(){
this.status = 0;
this.readyState = 0;
return this;
}
XMLHttpRequest.prototype.open = function(meth, uri, asyn){
if(!uri){
throw {};
}
@m1el
m1el / commands.sh
Last active December 19, 2015 09:59
git clone https://github.com/ariya/phantomjs.git
cd phantomjs
git checkout f6abcfe67620f8fdceae89cc4ba0451c37a3ef9d
wget https://gist.github.com/m1el/5937163/raw/68f1b1f34296ccf68008c1c0b28bdb1faf3371fe/phantomjs-exec-patch.diff
patch -p1 < phantomjs-exec-patch.diff
# configure, make
//.386
//.model tiny
//.code
//org 100h
function init_graphics() {
document.body.appendChild(canvas = document.createElement('canvas'))
canvas.width = 640
canvas.height = 480
ctx = canvas.getContext('2d')
var data = ctx.getImageData(0,0, 640,480),
@m1el
m1el / gen_lucky.py
Last active December 21, 2015 01:39
def gen_sum(n, s, base=10, startwith=None):
startwith = startwith or []
start = int(startwith[0]) if len(startwith) > 0 else -1
if n == 1:
if s < base:
yield str(s)
else:
for i in range(max(0, start, s - (n - 1) * (base - 1)), min(s, base - 1) + 1):
for sub in gen_sum(n - 1, s - i, base, startwith[1:] if i == start else None):
yield str(i) + sub
// solver for http://www.dota2.com/quiz
setInterval(function() {
$.map(g_Solution, function(e) {
$('#sourceItems, #recipeItem')
.find('div[style*="' + e.img + '"]:not(.disabled):eq(0)')
.trigger('mousedown');
});
}, 2500);
@m1el
m1el / astar.js
Created September 6, 2013 22:49
A* path finding implementation in js
function astar_path(field, start, end) {
start = {x: start.x, y: start.y, cost: 0};
var queue = [start],
visited = {},
node;
visited[start.x + ':' + start.y] = start;
while ((node = queue.shift())) {
var neighbors = get_neighbors(field, node);
if (get_distance(node, end) === 0) {
@m1el
m1el / gist:6476540
Created September 7, 2013 15:24
python vs. perl hello world syscalls count
m1el@blackninja:~$ strace python -c 'print "hello world"' 2>&1 | wc -l
784
m1el@blackninja:~$ strace perl -e 'print "hello world"' 2>&1 | wc -l
169
function $x(xpath, root) {
root = root ? root : document;
try {
var nodes = document.evaluate(xpath, root, null, 7, null);
} catch(e) {
return [];
}
var result = [];
for(var i = 0; i < nodes.snapshotLength; i++) {
result[i] = nodes.snapshotItem(i);
@m1el
m1el / fear2.1.theme
Created October 26, 2013 11:25
slightly modified fear2 irssi theme
# When testing changes, the easiest way to reload the theme is with /RELOAD.
# This reloads the configuration file too, so if you did any changes remember
# to /SAVE it first. Remember also that /SAVE overwrites the theme file with
# old data so keep backups :)
# TEMPLATES:
# The real text formats that irssi uses are the ones you can find with
# /FORMAT command. Back in the old days all the colors and texts were mixed
# up in those formats, and it was really hard to change the colors since you