Skip to content

Instantly share code, notes, and snippets.

View nicholasbs's full-sized avatar

Nicholas Bergson-Shilcock nicholasbs

View GitHub Profile
@nicholasbs
nicholasbs / fade.js
Created July 14, 2011 18:23
fadeIn and fadeOut functions that work on elements or ids (no libs required)
// 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);
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;
};
}
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.
@nicholasbs
nicholasbs / gist:3189198
Created July 27, 2012 17:08
Super simple "pub-sub" code
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) {
@nicholasbs
nicholasbs / gist:3259846
Created August 4, 2012 20:50
Implementing the "new" operator in JavaScript
// 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 / example1.html
Created August 20, 2012 18:22
Example 1 (Chrome profiler)
<html>
<head>
<script>
function makeClosure () {
var str = "This string was closed over";
return function () {
console.log(str);
};
};
(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

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

@nicholasbs
nicholasbs / gist:4280863
Created December 13, 2012 22:54
How are variables passed to functions in JavaScript?
/*
* 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++;
}
@nicholasbs
nicholasbs / gist:3327493
Created August 11, 2012 21:47
A (very) quick introduction to garbage collection
// 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 ||