Skip to content

Instantly share code, notes, and snippets.

View njvack's full-sized avatar

Nate Vack njvack

View GitHub Profile
@njvack
njvack / make_lags.py
Created June 28, 2018 19:23
LAG generator for Mnemonic Similarity Task
#!/usr/bin/env python
"""
Compute stimulus orderings for the mnemonic similarity task, described in:
Stark SM, Stevenson R, Wu C, Rutledge S, & Stark CEL (2015). Stability of
age-related deficits in the mnemonic similarity task across task variations.
Behavioral Neuroscience 129(3), 257-268.
Written by Nate Vack <[email protected]> at the Center for Healthy Minds,
University of Wisconsin-Madison, for the mp2 study conducted by Dan Grupe
@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: [email protected]
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
@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.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 / 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 / README.md
Last active February 8, 2024 21:43
Color to hex and rgba converter

Simple canvas-based color converter

To answer this StackOverflow question I wrote this — a small solution based on a never-rendered <canvas> element. It fills a 1-pixel canvas with the provided fill-style, and then reads the RGBA values of that pixel. It will work with any CSS color -- name, rgba(), hex, or even something more exotic like a gradient or pattern. Invalid colors are always returned as transparent black. Transparent colors are treated as painted on a newly-cleared canvas.

It's been tested in modern-ish versions of IE, Chrome, Safari, and Firefox. The API is:

color_convert.to_hex(color)   # Converts color to a hex-based RGB triple; to_hex('red') returns '#ff0000'
color_convert.to_rgba(color)  # Converts color to an rgba() string; to_rgba('red') returns 'rgba(255,0,0,1)'
@njvack
njvack / A Slicing Thing.ipynb
Created March 13, 2015 14:11
A Slicing Notebook
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@njvack
njvack / index.html
Last active February 20, 2019 14:45 — forked from mbostock/.block
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.node {
font: 300 11px "Helvetica Neue", Helvetica, Arial, sans-serif;
fill: #bbb;
}
.node:hover {
@njvack
njvack / coins_login.rb
Created June 23, 2014 21:08
A little Ruby Mechanize script to force logging in to Coins. The web standards, they have not been followed at all.
#!/usr/bin/env ruby
require 'mechanize'
require 'pp'
def coins_login(agent, username, password)
page = agent.get "https://chronus.mrn.org/cas/login.php?rp=https%3A%2F%2Fchronus.mrn.org%2Fmicis%2Findex.php%3Fsubsite%3Dasmt"
uname_match = page.body.match /name="([^"]+)" placeholder="Username/
uname_field = uname_match[1]
pw_match = page.body.match /name="([^"]+)" placeholder="Pa\$\$w0rd/
@njvack
njvack / upload_gating_files
Created May 23, 2014 20:07
Upload gating files from a GE MRI scanner
#!/bin/bash
GATING_DIR=${GATING_DIR:-/usr/g/service/log/gating}
DEST_BASE=${DEST_BASE:-/mri-upload/ge_physio}
MAX_AGE_MINUTES=${3:-120}
study=$1
ppt=$2
if [[ "${study}" == "" ]] || [[ "${ppt}" == "" ]] || [[ "${study}" == "-h" ]]; then