Skip to content

Instantly share code, notes, and snippets.

View jimfleming's full-sized avatar

Jim Fleming jimfleming

View GitHub Profile
@jimfleming
jimfleming / levenshtein.coffee
Created August 15, 2012 15:44
Fuzzy string comparison
# Based on: http://seatgeek.com/blog/dev/fuzzywuzzy-fuzzy-string-matching-in-python
_ = require 'underscore'
token_regex = /\w+/g
trim_regex = /^\s+|\s+$/g
levenshtein_dist = (a, b) ->
throw new TypeError('a is empty') unless _.isString(a)
throw new TypeError('b is empty') unless _.isString(b)
@jimfleming
jimfleming / set.go
Created April 5, 2013 05:13
A simple set data structure in go.
package set
type Set map[interface{}]struct{}
func (this *Set) Contains(m *interface{}) (exists bool) {
s := *this
_, exists = s[m]
return
}
@jimfleming
jimfleming / genome.coffee
Created April 8, 2013 04:37
Reads a 23andme genome download into redis
fs = require 'fs'
path = require 'path'
redis = require('redis').createClient()
multi = redis.multi()
console.log 'Reading...'
fileName = process.argv.slice(-1)[0]
filePath = path.join process.cwd, fileName
fileStream = fs.createReadStream filePath
@jimfleming
jimfleming / approx_tanh.go
Last active December 17, 2015 18:18
Approximate hyperbolic tangent function (-15x-, nevermind, post Go 1.1 only 2x faster than `math.tanh`)
func ApproxTanh(x float64) float64 {
if x > 21 {
return 1
}
if x < -21 {
return -1
}
if x == +0 {
return +0
}
@jimfleming
jimfleming / bounds.cs
Created June 25, 2013 04:18
Sizes a bounding box to its children.
BoxCollider collider = gameObject.AddComponent<BoxCollider>();
Bounds parentBounds = new Bounds(Vector3.zero, Vector3.zero);
Bounds childBounds = new Bounds(Vector3.zero, Vector3.zero);
MeshFilter[] meshFilters = transform.GetComponentsInChildren<MeshFilter>();
foreach (MeshFilter meshFilter in meshFilters) {
childBounds.center = transform.InverseTransformPoint(meshFilter.renderer.bounds.center);
childBounds.size = meshFilter.sharedMesh.bounds.size;
parentBounds.Encapsulate(temp);
}
@jimfleming
jimfleming / blur.py
Created July 3, 2013 17:08
Naive blur implementation
from math import sqrt, exp, pi
import pygtk
pygtk.require('2.0')
import gtk
import numpy as np
def make_kernel(radius):
width = radius * 2 + 1
@jimfleming
jimfleming / sciblur.py
Created July 3, 2013 17:08
Gaussian blur using scipy
from math import ceil
import pygtk
pygtk.require('2.0')
import gtk
import numpy as np
from scipy import ndimage
@jimfleming
jimfleming / UnityDiffuseLightmap.shader
Last active June 21, 2023 00:44
Example depicting applying Unity lightmapping data to a simple diffuse shader.
Shader "Diffuse Lightmap" {
Properties {
_MainTex ("Texture 1", 2D) = "white" {}
}
SubShader {
Tags { "RenderType" = "Opaque" }
Pass {
def unfreezeTransformations(selection):
originalCenter = cmds.getAttr('%s.center' % selection)[0]
cmds.move(originalCenter[0] * -1, originalCenter[1] * -1, originalCenter[2] * -1, selection, absolute=True)
cmds.makeIdentity(selection, apply=True, translate=1, rotate=1, scale=1, normal=0)
cmds.move(originalCenter[0], originalCenter[1], originalCenter[2], selection, absolute=True)
@jimfleming
jimfleming / blend.shader
Last active December 28, 2015 10:59
Moving blobs used as interpolation values between two images.
#define INTENSITY 6.5
float blob(vec2 uv, vec2 speed, float time) {
// Compute a moving point
vec2 point = vec2(
sin(speed.x * time),
cos(speed.y * time)
);
float d = 1.0 / distance(uv, point) / INTENSITY;