Skip to content

Instantly share code, notes, and snippets.

View njvack's full-sized avatar

Nate Vack njvack

View GitHub Profile
@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 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 / 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 / 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 / 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 / index.html
Created October 26, 2011 16:08
Beeswarm plot with gravity and collisions
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Beeswarm plot - collision detection</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.geom.js"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.layout.js"></script>
</head>
<body>
@njvack
njvack / index.html
Last active December 21, 2016 21:38
Blinken
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<script type="text/javascript">
window.console = window.console || {}
window.console.log = window.console.log || function() {};
console.log("Hello");
@njvack
njvack / convert.py
Last active April 21, 2017 20:03
Three to four-byte conversion
def convert_three_byte(frame):
data_out = np.zeros(128, dtype=np.int32) # You're looking to make a 128-element array of int32.
data_out.dtype = np.byte
data_out = data_out.reshape(-1, 4) # Shape is now (128,4) and dtype is byte
# Now, copy the data from chans08to00 into data_out. We need to specify which bytes to put it in.
# Also, we need to reverse the data in frame.
# You'd change 0:3 to 1:4 if the stuff in frame is big-endian, I think? You'll need to experiment.
data_out[0:8, 0:3] = frame['chans08to00'][::-1]
# ... and so on with channels
data_out.dtype = np.int32
@njvack
njvack / dos_line_endings.py
Created July 31, 2017 18:24
Python script to normalize CSV files (remove UTF-8 sig, change line endings to CRLF)
#!/usr/bin/env python
"""
Usage: dos_line_endings
Takes stdin, changes all line endings from \r or \n to \r\n, strips UTF-8
byte-order mark (if any), writes to stdout.
"""
import sys
import re
@njvack
njvack / convert_dcm2niix.sh
Created October 11, 2017 23:02
Convert tarfile of dicoms
#!/bin/bash
# Written by Jonah Chaiken and Nate Vack
# Support: bit_help@lists.wisc.edu
help=" Usage: convert_dcm2niix.sh <in_file> <out_file>
This program will individually convert a dicom archive file to a NIfTI file.
The input can be either a .tar file containing bzip2'd dicom slices, or a