Skip to content
Search Gists
Sign in Sign up

Instantly share code, notes, and snippets.

Nathan Agrin n8agrin

🐢
Built a life around sliding on water.
View GitHub Profile
n8agrin / linear_scale.js
Created March 22, 2013 22:26
Simplified linear scale based on d3.
function uninterpolate (a, b, x) {
b = b - (a = +a) ? 1 / (b - a) : 0;
return (x - a) * b;
}
function interpolate (a, b, t) {
return (a + (b - a)) * t;
}
// Given a domain [0, 10], a range [0, 100], and a value (v),
n8agrin / README.md
Last active December 11, 2015 02:09 — forked from mbostock/.block

This stacked bar chart is constructed from a CSV file storing the populations of different states by age group. The chart employs conventional margins and a number of D3 features:

n8agrin / README.md
Last active December 11, 2015 02:09 — forked from mbostock/.block
n8agrin / kruskal.js
Created September 5, 2012 02:33
Simple Kruskal's implementation
// See http://en.wikipedia.org/wiki/Kruskal's_algorithm
// and http://programmingpraxis.com/2010/04/06/minimum-spanning-tree-kruskals-algorithm/
var _ = require('underscore');
var nodes = ["A", "B", "C", "D", "E", "F", "G"];
var edges = [
["A", "B", 7], ["A", "D", 5],
n8agrin / myclass.js
Created May 15, 2012 18:12
A simple, if old, class system for Javascript.
// The best javascript class system ever! This is old news to most, but
// more and more I find myself coming back to this. I don't have a vendetta
// against the `new` keyword. I just sometimes want encapsulation in a way
// that doesn't feel like a complete hack.
// Start with a closure
var vehicle = function() {
// Use Object.create
var vehicle = Object.create({});
class Foo
constructor: ->
name: ->
@bar = 'foo'
# Javascript variant
var ListingsController = {
"index": function(req, res) {
var listings = listing.Listing.find({}, function(err, docs) {
res.send(docs);
});
},
"create": function(req, res) {
n8agrin / zeroneortwo.rb
Created April 17, 2011 16:36
create a naive generator that returns zero, one or two in even, random distribution
We couldn’t find that file to show.
from splunk import auth, entity
from remoteobjects import fields, RemoteObject
class SplunkObject(RemoteObject):
@classmethod
def get_path(cls):
return None
n8agrin / filemonitor.py
Created May 14, 2010 08:54
Simple file monitoring in python
import os, time
last_modified = None
def ease_sleep():
now = time.time()
if (now - last_modified) < 1:
print 'sleeping less'
time.sleep(0.001)
else:
time.sleep(1)
NewerOlder

AltStyle によって変換されたページ (->オリジナル) /