Skip to content

Instantly share code, notes, and snippets.

View paulkaplan's full-sized avatar

Paul Kaplan paulkaplan

View GitHub Profile
@paulkaplan
paulkaplan / colorTempToRGB.js
Last active March 4, 2024 10:29
Color Temperature to RGB
// From http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
// Start with a temperature, in Kelvin, somewhere between 1000 and 40000. (Other values may work,
// but I can't make any promises about the quality of the algorithm's estimates above 40000 K.)
function colorTemperatureToRGB(kelvin){
var temp = kelvin / 100;
@paulkaplan
paulkaplan / index.js
Created February 24, 2013 04:11
voxel.js game
var createGame = require('voxel-engine')
function sphereWorld(x, y, z) {
// return the index of the material you want to show up
// 0 is air
if (x*x + y*y + z*z > 15*15) return 0
return 3
}
var game = createGame({
@paulkaplan
paulkaplan / index.js
Created February 24, 2013 04:07
voxel.js game
var createGame = require('voxel-engine')
function sphereWorld(x, y, z) {
// return the index of the material you want to show up
// 0 is air
if (x*x + y*y + z*z > 15*15) return 0
return 3
}
var game = createGame({
@paulkaplan
paulkaplan / index.js
Created February 24, 2013 03:59
voxel.js game
var createEngine = require('voxel-engine')
var game = createEngine({
generate: function(x, y, z) {
if (x*x + y*y + z*z > 20*20) return 0;
return Math.floor(Math.random() * 4) + 1;
},
texturePath: './',
materials: [ 'dirt', 'grass', 'crate', 'brick' ]
});
game.appendTo('#container');
@paulkaplan
paulkaplan / Scene.rb
Created January 29, 2013 06:50
Scene writer for POVRay, with a simple ruby API
class Scene
attr_accessor :lights, :objects, :camera
def initialize
@lights = []
@objects = []
end
def add_light light
@lights.push light
end
class STL
class Writer
attr_accessor :tris, :size
def initialize tris
@tris = tris
@size = tris.length*50 + 80 + 4
end
def write_stl_header f
80.times {|n| f << [0].pack("C") } #uint8
@paulkaplan
paulkaplan / gist:3036353
Created July 2, 2012 23:24 — forked from olistik/gist:2627011
Ubuntu 12.04 setup (rbenv, janus, postgres)

Basic pre-requisites

  • Some utilities:
sudo apt-get install vim tmux git
  • Copy/paste from the command line:
sudo apt-get install xclip
@paulkaplan
paulkaplan / listing.c
Created November 22, 2011 19:43
Post listing to rails app with Devise token-authenticable from Objective-C
// QUESTION: For some reason Devise only sees auth token when passed through url not as param
// WHY? this seems really insecure...
-(NSString *) concatURL {
NSString *base = @"http://localhost:3000";
NSString *auth = [[NSUserDefaults standardUserDefaults] objectForKey:@"token"];
return [NSString stringWithFormat:@"%@?auth_token=%@", base, auth];
}
-(NSDictionary *) postListing {
@paulkaplan
paulkaplan / listing.c
Created November 22, 2011 19:39
Requesting and parsing json data from rails app in objective-c
+(NSMutableArray *) loadRemoteListings {
NSMutableArray *listings = [NSMutableArray arrayWithCapacity:20];
NSURL *url = [[NSURL alloc] initWithString:@"http://localhost:3000"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
NSURLResponse *response;
NSError *error;
@paulkaplan
paulkaplan / listing.c
Created November 22, 2011 19:39
Requesting and parsing json data from rails app in objective-c
+(NSMutableArray *) loadRemoteListings {
NSMutableArray *listings = [NSMutableArray arrayWithCapacity:20];
NSURL *url = [[NSURL alloc] initWithString:@"http://localhost:3000"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
NSURLResponse *response;
NSError *error;