Skip to content

Instantly share code, notes, and snippets.

View njvack's full-sized avatar

Nate Vack njvack

View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<title>Circley</title>
<style type="text/css">
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
width: 960px;
height: 500px;
position: relative;
@njvack
njvack / catmullrom2bezier.js
Created October 10, 2013 21:01
A routine to compute the cubic Bézier spline parameters to fit a curve to points, using the Catmull-Rom algorithm.
//************************************************
//
// Catmull-Rom Spline to Bezier Spline Converter
//
//
// This is an experimental extension of the SVG 'path' element syntax to
// allow Catmull-Rom splines, which differs from Bézier curves in that all
// defined points on a Catmull-Rom spline are on the path itself.
//
// This is intended to serve as a proof-of-concept toward inclusion of a
#!/usr/bin/env ruby
require 'rubygems'
require 'mysql2'
Mysql2::Client.default_query_options.merge!(:as => :array)
conn = Mysql2::Client.new(:host => 'localhost', :username => 'user',
:password => 'pw', :database => 'db')
tables = conn.query("SHOW TABLES").map {|row| row[0] }
@njvack
njvack / index.html
Created November 15, 2012 18:35
Circle packing, study data
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<style>
text { font: 10px sans-serif; }
</style>
</head>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
@njvack
njvack / expressify.py
Created September 21, 2012 02:30
My stab at safe python evaluation
import ast
import math
SAFE_FX = {
'exp': math.exp,
}
SAFE_NODES = set(
(ast.Expression,
ast.Num,
@njvack
njvack / memory_watch.rb
Created April 12, 2012 01:33
A slightly-overengineered utility to watch signal memory-hungry unicorn workers
#!/usr/bin/env ruby
class HumanBinarySize
MATCHER = /([\d_,]+) *([kmgtp])?b?/i
MULTIPLIER = {
'b' => 1,
'k' => 2**10,
'm' => 2**20,
'g' => 2**30,
@njvack
njvack / dabblet.css
Created March 1, 2012 21:59
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
background: #f00;
background: linear-gradient(-90deg, #a0d, yellow);
min-height:100%;
@njvack
njvack / index.html
Created February 6, 2012 15:06
HTML nesting test
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Test</title>
</head>
<body>
<div style="width: 500px; background-color:#F33;">
This is the outer div
<div style="background-color: #FAA; padding: 10px; margin:10px;">
@njvack
njvack / hostname_middleware.py
Created February 3, 2012 19:38
Trivial fix for HTTP_HOST problems with reverse-proxied Django
"""
Simply copies the X_FORWARDED crap into HTTP_HOST and SERVER_NAME.
"""
class SetHostname(object):
def process_request(self, request):
request.META['HTTP_HOST'] = request.META['HTTP_X_FORWARDED_HOST']
request.META['SERVER_NAME'] = request.META['HTTP_X_FORWARDED_SERVER']
@njvack
njvack / index.html
Created January 8, 2012 05:45
Pan run simulator
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Pan math fun</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"> </script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"> </script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.layout.js"> </script>
<script type="text/javascript">