Skip to content

Instantly share code, notes, and snippets.

View kgryte's full-sized avatar
😃
Working on stdlib...

Athan kgryte

😃
Working on stdlib...
View GitHub Profile
@IcyMidnight
IcyMidnight / MySQL functions to convert between binary and string uuids
Created July 31, 2009 09:27
MySQL functions to convert between binary and string uuids
DELIMITER |
CREATE FUNCTION uuid_from_bin(b BINARY(16))
RETURNS CHAR(36) DETERMINISTIC
BEGIN
DECLARE hex CHAR(32);
SET hex = HEX(b);
RETURN CONCAT(LEFT(hex, 8), '-', MID(hex, 9,4), '-', MID(hex, 13,4), '-', MID(hex, 17,4), '-', RIGHT(hex, 12));
END
|
@banksean
banksean / mersenne-twister.js
Created February 10, 2010 16:24
a Mersenne Twister implementation in javascript. Makes up for Math.random() not letting you specify a seed value.
/*
I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace
so it's better encapsulated. Now you can have multiple random number generators
and they won't stomp all over eachother's state.
If you want to use this as a substitute for Math.random(), use the random()
method like so:
var m = new MersenneTwister();
@Gozala
Gozala / extend-array.js
Created November 7, 2010 17:10
Array subclass ES5
// No need to sub class Array if what you need is just an extended
// array. Example below illustrates the way to extend Array.
function SubArray() {
return Object.defineProperties(Array.prototype.slice.call(arguments), SubArrayDescriptor)
}
SubArray.prototype = Array.prototype
var SubArrayDescriptor =
{ constructor: { value: SubArray }
, last: { value: function last() {
@mathiasbynens
mathiasbynens / appify
Created November 12, 2010 13:46 — forked from subtleGradient/appify
appify — create the simplest possible Mac app from a shell script
#!/bin/bash
if [ "$1" = "-h" -o "$1" = "--help" -o -z "$1" ]; then cat <<EOF
appify v3.0.1 for Mac OS X - http://mths.be/appify
Creates the simplest possible Mac app from a shell script.
Appify takes a shell script as its first argument:
`basename "$0"` my-script.sh
anonymous
anonymous / gist:729557
Created December 5, 2010 22:41
64-bit unsigned integer cube root
#include <stdio.h>
typedef unsigned int U32;
typedef unsigned __int64 U64;
// ---- actual cube root code
U32 icbrt64(U64 x) {
int s;
U32 y;
@coreyhaines
coreyhaines / churn script
Created February 16, 2011 19:04
Bash script to generate churn counts in git repo
churn number and file name
git log --all -M -C --name-only | grep -E '^(app|lib)/' | sort | uniq -c | sort | awk 'BEGIN {print "count,file"} {print $1 "," $2}'
churn number and file name w/ limiting to last n commits
git log --all -n 5000 -M -C --name-only | grep -E '^spec/models' | sort | uniq -c | sort | awk 'BEGIN {print "count,file"} {print $1 "," $2}'
graph of churn number and frequency
git log --all -M -C --name-only | grep -E '^(app|lib)/' | sort | uniq -c | sort | awk '{print $1}' | uniq -c | sort | awk 'BEGIN { print "frequency,churn_count"} { print $1,$2}'
var matrix = {}
matrix.new = function (n) {
var a = new Array(n);
for (var i = 0; i < n; i++) a[i] = new Float64Array(n);
return a;
}
matrix.T = function (a, n) {
var y = matrix.new(n)
@armon
armon / facebook.py
Created May 20, 2011 07:17
Facebook interface to get posts and perform hierarchical user clustering
from collections import defaultdict
from math import sqrt
import httplib2
import json
import re
import threadpool
import threading
from PIL import Image,ImageDraw
ACCESS_TOKEN = "..."
@jed
jed / LICENSE.txt
Created May 20, 2011 13:27 — forked from 140bytes/LICENSE.txt
generate random UUIDs
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@avibryant
avibryant / loess.js
Created August 17, 2011 15:45
Loess smoothing
//adapted from the LoessInterpolator in org.apache.commons.math
function loess_pairs(pairs, bandwidth)
{
var xval = pairs.map(function(pair){return pair[0]});
var yval = pairs.map(function(pair){return pair[1]});
console.log(xval);
console.log(yval);
var res = loess(xval, yval, bandwidth);
console.log(res);
return xval.map(function(x,i){return [x, res[i]]});