Skip to content

Instantly share code, notes, and snippets.

View jlfwong's full-sized avatar

Jamie Wong jlfwong

View GitHub Profile
// http://bgrins.github.io/devtools-snippets/#console-save
var saveToFile = function(data, filename) {
if (!data) {
console.error('Console.save: No data');
return;
}
if (!filename) {
filename = 'console.json';
}
// Handy for debugging sometimes
function tap(fn) {
return function() {
const result = fn.apply(this, arguments);
console.log(Array.prototype.slice.call(arguments), '->', result);
return result;
}
}
@jlfwong
jlfwong / Makefile
Last active August 29, 2015 13:57
CS444 runtime.s for OS X
.PHONY: run
run: test
./$<
test: test.o runtime.o
gcc -arch i386 $^ -o $@
%.o: %.asm
nasm -f macho $< -o $@
@jlfwong
jlfwong / fbchat-to-markdown-blockquote.js
Last active January 1, 2016 00:29
Format FB chats into markdown for pasting into Day One Dump this into the JS console
// http://bgrins.github.io/devtools-snippets/#console-save
var saveToFile = function(data, filename) {
if (!data) {
console.error('Console.save: No data');
return;
}
if (!filename) {
filename = 'console.json';
}
@jlfwong
jlfwong / foobar.js
Created December 10, 2013 22:08
Automatic Semicolon Insertion - Scala vs JavaScript
var foo = function() { console.log("foo"); };
var bar = function() { console.log("bar"); };
(foo())
(bar())
/*
Ouput:
(bar())
@jlfwong
jlfwong / RequireJSsubprocess.md
Created September 29, 2013 19:24
Require JS Subprocess Rubber Ducky Log

Building the package! RequireJS plugin, I'm getting weird side effect problems.

Requiring a package first:

> require(["package!issues.js"]); null
null
Require Package: issues.js package_loader_plugin.js?bust=1379092758956:96
XHR finished loading: "http://localhost:1234/javascript-packages.json".

jquery.js?bust=1379092758956:8526

@jlfwong
jlfwong / gist:6031820
Last active December 19, 2015 22:59
Changing soft tab size in vim

Changing 4 space indentation into 2 space indentation

:set ts=4 noexpandtab | retab! | set ts=2 expandtab | retab!

Changing 4 space indentation in every CoffeeScript file in your current directory

:args ./**/*.coffee | argdo execute "set ts=4 noexpandtab | retab! | set ts=2 expandtab | retab!" | update

Thanks to bamford on #vim for the :retab! trick

@jlfwong
jlfwong / progdiff.sh
Created October 3, 2012 20:07
Diff the stdout, stderr and return code of two programs with piped input and arguments
#!/bin/bash
sandbox="$(mktemp -d)"
hasstdin=false
if [ ! -t 0 ]; then
cat <&0 > "$sandbox/stdin.txt"
hasstdin=true
fi
@jlfwong
jlfwong / handler.py
Created May 10, 2012 15:02
ENV server->js data pattern
Why this is useful:
1. All data in ENV is coming from the server, so it's easy to differentiate data coming from the server and static data when reading through JS.
2. If you put the {{ env_js }} in the root template, it'll be usable by in all templates that inherit from it. That means you don't need to adjust the template to share data to the client-side.
3. Only one new global variable instead of one per thing coming from the server.
@jlfwong
jlfwong / pdb_on_error.py
Created May 7, 2012 18:00
pdb debug decorator
from functools import wraps
import sys
import pdb
import traceback
def pdb_on_error(func):
@wraps(func)
def pdbd(*args, **kwargs):
try:
func(*args, **kwargs)