Skip to content

Instantly share code, notes, and snippets.

View njvack's full-sized avatar

Nate Vack njvack

View GitHub Profile
@njvack
njvack / link_tree
Last active August 29, 2015 14:00
Make symlinks from a directory's file structure out on the filesystem
#!/usr/bin/env ruby
require 'tmpdir'
require 'fileutils'
fix_file = ARGV[0]
vid_file = ARGV[1]
out_file = ARGV[2]
FIXATION_FRAMES=10
VID_FRAMES=25
@njvack
njvack / convert_tarred_dicoms
Last active August 29, 2015 13:57
A wrapper to allow Freesurfer's mri_convert to work on a tarball of dicoms.
#!/bin/bash
in_file="$1"
out_file="$2"
out_base=$(dirname "${out_file}")
tmp_dir=$(mktemp -d -p "${out_base}")
if [ $? -ne 0 ]; then
echo "Can't make a temporary directory in ${out_base}" >&2
@njvack
njvack / mask_scramble.py
Created March 6, 2014 19:12
A script to randomize the pixels in an image, so long as they're within a mask.
#!/usr/bin/env python
import sys
import argparse
from PIL import Image
import numpy as np
def scramble_ary(img_ar, mask_ar):
"""
<!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,