Skip to content

Instantly share code, notes, and snippets.

Avatar

Ian Bicking ianb

View GitHub Profile
@ianb
ianb / new.js
Created Jan 28, 2013
Thinking about what the new operator really looks like, if you treat Object.create() as the more fundamental operation
View new.js
function new_(constructor /* arguments to constructor */) {
var args = Array.prototype.slice.call(arguments, 1);
var obj = Object.create(constructor.prototype);
var result = constructor.apply(obj, args);
if (result === undefined) {
result = obj;
}
return result;
}
@ianb
ianb / Class.js
Last active Dec 11, 2015
A simple implementation of a class pattern for Javascript
View Class.js
var Class = function (superClass, prototype) {
if (prototype === undefined) {
prototype = superClass;
} else {
var newPrototype = Object.create(superClass);
for (var a in prototype) {
newPrototype[a] = prototype[a];
}
prototype = newPrototype;
}
View .emacs.el
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(auto-save-file-name-transforms (quote (("\\`/[^/]*:\\(.+/\\)*\\(.*\\)" "/Users/ianbicking/.emacs-saves/autosave"))))
'(backup-directory-alist (quote ((".*" . "/Users/ianbicking/.emacs-saves/backup/"))))
'(delete-old-versions t)
'(flymake-allowed-file-name-masks (quote (("\\.\\(?:c\\(?:pp\\|xx\\|\\+\\+\\)?\\|CC\\)\\'" flymake-simple-make-init) ("\\.cs\\'" flymake-simple-make-init) ("\\.p[ml]\\'" flymake-perl-init) ("\\.php[345]?\\'" flymake-php-init) ("\\.h\\'" flymake-master-make-header-init flymake-master-cleanup) ("\\.java\\'" flymake-simple-make-java-init flymake-simple-java-cleanup) ("[0-9]+\\.tex\\'" flymake-master-tex-init flymake-master-cleanup) ("\\.tex\\'" flymake-simple-tex-init) ("\\.idl\\'" flymake-simple-make-init))))
'(frame-background-mode (quote
View gist:4162743
def make_adder(n):
def adder(x):
return n + x
return adder
two = make_adder(2)
print two.__code__.co_freevars
# => ('n',)
print two.func_closure[0].cell_contents
# => 2
@ianb
ianb / gist:4162673
Created Nov 28, 2012
smalltalk introspection?
View gist:4162673
Object extend [
makeAdder: value [
^ [ :x | x + value]
]
].
closure := Object new makeAdder: 5.
"Now: how to you inspect the closure object to reveal that x == 5 ?"
View threaded_fact.py
import threading
try:
from Queue import Queue
except ImportError:
from queue import Queue
def fact(n, queue=None):
if n == 0 or n == 1:
if queue:
View gist:3908920
Process: firefox [57590]
Path: /Users/USER/*/Nightly.app/Contents/MacOS/firefox
Identifier: org.mozilla.nightly
Version: 19.0a1 (1912.10.17)
Code Type: X86-64 (Native)
Parent Process: bash [57588]
User ID: 501
Date/Time: 2012-10-17 18:07:25.867 -0500
OS Version: Mac OS X 10.8.2 (12C60)
View example-gum.js
function supportsWebRTC() {
return !!(
(window.mozRTCPeerConnection || window.RTCPeerConnection)
&& (navigator.mozGetUserMedia || navigator.getUserMedia)
);
}
if (window.mozRTCPeerConnection) {
RTCPeerConnection = mozRTCPeerConnection;
}
View gist:3790838
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000
[Switching to process 21612 thread 0xb803]
fsm_init_fcb (fcb=0x0, call_id=0, dcb=0x0, type=FSM_TYPE_MIN) at /Users/ianbicking/src/mozilla-central-alder/media/webrtc/signaling/src/sipcc/core/gsm/fsm.c:147
147 fcb->call_id = call_id;
View gist:3790537
Process: firefox [21212]
Path: /Users/USER/*/Nightly.app/Contents/MacOS/firefox
Identifier: org.mozilla.nightly
Version: 18.0a1 (1812.9.26)
Code Type: X86-64 (Native)
Parent Process: bash [21210]
User ID: 501
Date/Time: 2012-09-26 15:55:57.986 -0500
OS Version: Mac OS X 10.8.1 (12B19)