Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jkosoy's full-sized avatar

Jamie Kosoy jkosoy

View GitHub Profile
@jkosoy
jkosoy / gist:2776908
Created May 23, 2012 18:34
Port of Processing's map() function to JS. See: http://processing.org/reference/map_.html
function map(val, a1, a2, b1, b2) { return ((val - a1) * (b2 -b1)/(a2 - a1)) + b1; }
@jkosoy
jkosoy / perlin-noise-simplex.js
Created May 23, 2012 18:35 — forked from banksean/perlin-noise-classical.js
Minified Perlin Noise Simplex.
// https://gist.github.com/304522
// Ported from Stefan Gustavson's java implementation
// http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
// Read Stefan's excellent paper for details on how this code works.
//
// Sean McCullough banksean@gmail.com
/**
* You can pass in a random number generator object if you like.
* It is assumed to have a random() method.
git checkout develop
git log -1
git checkout translation
git cherry-pick [commit hash goes here]
@jkosoy
jkosoy / Index of an item, given it's X and Y
Created May 24, 2012 22:17
Grid Math (useful for image pixel data, too!)
index = (y*rows)+x;
@jkosoy
jkosoy / gist:2784493
Created May 24, 2012 22:08
Excel Formulas for Mint
Export your Mint data to CSV.
Import to Excel or equivalent.
Trim the data down to just the date range you need (Mint doesn’t allow this out of the box).
Add a few columns to contain your totals and drop in these formulas:
=SUMIF(E:E,”debit”,D:D)
// Auto & Transport
=IF(E:E=”debit”,SUM(SUMIF(F:F,”Auto & Transport”,D:D),SUMIF(F:F,”Auto Insurance”,D:D),SUMIF(F:F,”Auto Payment”,D:D),SUMIF(F:F,”Gas & Fuel”,D:D),SUMIF(F:F,”Parking”,D:D),SUMIF(F:F,”Service & Parts”,D:D),SUMIF(F:F,”Public Transportation”,D:D)),0)
Because I always forget...
// Get the angle between two points
atan2(y2-y1,x2-x1);
// Get the x and y of an object around a radius, given an angle.
x = cos(radians(angle)) * radius
@jkosoy
jkosoy / alphabet
Created July 2, 2012 22:07
Alphabet. Just thought this looked neat.
var a = function() {
var b = function() {
var c = function() {
var d = function() {
var e = function() {
var f = function() {
var g = function() {
var h = function() {
var i = function() {
var j = function() {
@jkosoy
jkosoy / gist:4113485
Created November 19, 2012 19:59
HTML5 Image Resize
function resizeImage($img,$w,$h) {
var maxWidth = $w;
var maxHeight = $h;
var w = $img.width;
var h = $img.height;
if(w > h) {
if(w > maxWidth) {
h *= maxWidth/w;
@jkosoy
jkosoy / .bash_profile
Last active October 13, 2015 02:38
Bash Profile Settings.
alias ls='ls -GFh'
export CLICOLOR=1
# From Andrzej Szelachowski's ~/.bash_profile:
# Note that a variable may require special treatment
#+ if it will be exported.
DARKGRAY='\[\e[1;30m\]'
@jkosoy
jkosoy / gist:4359595
Created December 22, 2012 15:58
NSLog datatypes, courtesy http://snipplr.com/view/21403/
NSLog(@"%@", [NSNumber numberWithInt:i]);
/*
%@ Object
%d, %i signed int
%u unsigned int
%f float/double
%1.2f to controll number of decimals
%x, %X hexadecimal int