Skip to content

Instantly share code, notes, and snippets.

Nicholas Bergson-Shilcock nicholasbs

Block or report user

Report or block nicholasbs

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nicholasbs
nicholasbs / gist:4280863
Created Dec 13, 2012
How are variables passed to functions in JavaScript?
View gist:4280863
/*
* JavaScript variables are always passed by value. This works as you
* expect it to when you pass primitives to functions.
*/
function add1(x) {
// We get passed a copy of x's value -- which is a number -- so we can't
// update the original variable's value
x++;
}
View david.markdown

LinkedList NYC Program

inside this file is a webserver that will output the text "LinkedList NYC" on network port 31337 via HTTP.

killin' it

executes with ruby 1.9.3

View andrew.scm
(define (ntbf-eval
x h d) (unless (null? x) (case
(car x) ((#\>) (ntbf-eval (cdr x) h
(+ d 1))) ((#\<) (ntbf-eval (cdr x) h
(- d 1))) ((#\+) (begin (vector-set! h d
(+ 1 (vector-ref h d))) (ntbf-eval (cdr x)
h d))) ((#\-) (begin (vector-set! h d (-
1 (vector-ref h d))) (ntbf-eval (cdr x)
h d))) ((#\.) (begin (format #t "~a" (
integer->char (vector-ref h d))) (ntbf-eval
@nicholasbs
nicholasbs / example1.html
Created Aug 20, 2012
Example 1 (Chrome profiler)
View example1.html
<html>
<head>
<script>
function makeClosure () {
var str = "This string was closed over";
return function () {
console.log(str);
};
};
@nicholasbs
nicholasbs / gist:3327493
Created Aug 11, 2012
A (very) quick introduction to garbage collection
View gist:3327493
// When you create a new object
var obj = {data: "some data here"};
/* The JavaScript runtime environment allocates memory for you.
__________________________
Your computer's memory ----> || Location || Value ||
||------------------------||
It has to store that obj is || 0 || 2424 ||
an object, that it has a || 1 || 1002 ||
property named data, and || 2 || 327871 ||
@nicholasbs
nicholasbs / gist:3259846
Created Aug 4, 2012
Implementing the "new" operator in JavaScript
View gist:3259846
// New is a function that takes a function F
function New (F) {
var o = {}; // and creates a new object o
o.__proto__ = F.prototype // and sets o.__proto__ to be F's prototype
// New returns a function that...
return function () {
F.apply(o, arguments); // runs F with o as "this", passing along any arguments
return o; // and returns o, the new object we created
}
@nicholasbs
nicholasbs / gist:3189198
Created Jul 27, 2012
Super simple "pub-sub" code
View gist:3189198
REGISTRY = {}
function sub (name, cb, ctx) {
if (typeof REGISTRY[name] === "undefined") {
REGISTRY[name] = [];
}
return REGISTRY[name].push({cb: cb, ctx: ctx || null});
}
function pub (name) {
View gist:2881812
The 2012 Programming Languages Day will be held at the IBM Thomas J.
Watson Research Center on Thursday, June 28, 2012. The day will be held in
cooperation with the New Jersey and New England Programming Languages and
Systems Seminars. The main goal of the event is to increase awareness of
each other's work, and to encourage interaction and collaboration.
The Programming Languages Day features a keynote presentation and 8
regular presentations. Dr. Shriram Krishnamurthi of Brown University
will deliver the keynote presentation this year, "Securing JavaScript
on the Web". Details of the program are below.
View gist:2012547
function generate_math_operator(op) {
return function(args) {
var res = args[0], i, tmp;
for (i=1; i<args.length; i++) {
tmp = predicates.is_object(op) ? ast_to_js(op) : op;
res += " " + tmp + " " + args[i];
}
return res;
};
}
@nicholasbs
nicholasbs / fade.js
Created Jul 14, 2011
fadeIn and fadeOut functions that work on elements or ids (no libs required)
View fade.js
// TODO: IE support if I feel like it; make fade length directly configurable
(function() {
var DELTA = 0.06, // how much to change opacity each step
DURATION = 40; // how long in ms to pause between steps
function fadeFunc(direction, start, end) {
return function(el) {
el = typeof(el) == 'object' ? el : document.getElementById(el);
var step = function step() {
var opacity = el.style.opacity;
opacity = opacity === "" ? start : parseFloat(opacity);
You can’t perform that action at this time.