Skip to content

Instantly share code, notes, and snippets.

View njvack's full-sized avatar

Nate Vack njvack

View GitHub Profile
@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 / 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 / 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 python
"""
Takes a REDCap CSV file and splits it into:
* A file for each event
* A file for repeated instruments in events where they happen
So, if your data has events 'scr,' 'pre,' and 'post', and 'pre' and 'post'
each have a repeated instument called 'meds', you can expect
#!/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] }
"""
Generates an array blocks * block_len long, containing 1 and 2.
It's shuffled such that there can never be more than block_len
consecutive repetitions of either value.
"""
import numpy as np
blocks = 100
block_len = 8
groupnums = (np.arange(blocks * block_len) % 2) + 1
@njvack
njvack / sample-slack-coc.md
Last active March 13, 2020 17:18 — forked from annalee/sample-slack-coc.md
A sample code of conduct for social slack teams.

UW-Madison TechPartners Slack Code of Conduct

Welcome!

This Slack group is for any and everyone involved in tech at UW-Madison. Students, staff, faculty, alumni, and emeriti are all welcome. We're here to share tips and tricks, debate policy, but more importantly: to be a community.

The current admins are:

  • Nate Vack
@njvack
njvack / LICENSE
Last active January 16, 2020 14:45
Voronoi-based point picker
Copyright (c) 2020 Nathan Vack
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
# Binary builds
tap "homebrew/cask"
# Lets me get at things like sequel-pro-nightly
tap "homebrew/cask-versions"
# mas -> "Mac App Store"
brew "mas"
mas "Xcode", id: 497799835
brew "imagemagick"
@njvack
njvack / keybase.md
Created November 12, 2019 17:31
keybase.md

Keybase proof

I hereby claim:

  • I am njvack on github.
  • I am njvack (https://keybase.io/njvack) on keybase.
  • I have a public key ASB6TTOovVMHwUxq7IPCufRUK8WWK-MQlLVNO5USZ4C1lQo

To claim this, I am signing this object: