Skip to content

Instantly share code, notes, and snippets.

View coleww's full-sized avatar

Cole Willsea coleww

  • (=^.^=)
  • Berkeley, CA
View GitHub Profile
@coleww
coleww / gist:9403691
Last active August 29, 2015 13:57
Do two lines intersect? Processing/Java
//adapted from http://wiki.processing.org/w/Line-Line_intersection
//I do not understand how or why this works.
boolean intersects(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
float bx = x2 - x1;
float by = y2 - y1;
float dx = x4 - x3;
float dy = y4 - y3;
float b_dot_d_perp = bx * dy - by * dx;
@coleww
coleww / gist:9404486
Created March 7, 2014 02:55
Color picker for Processing
//TIRED OF INT(RANDOM(0, 255)) ALL OVER THE PLACE?
//get an array of colors from an image
//takes path to image, num of colors to grab, and whether to pick an even distribution or at random
color[] pickColors(String path, int numColors, boolean ordered) {
color[] colors = new color[numColors];
PImage img = loadImage(path);
img.loadPixels();
int numPixels = img.width * img.height;
@coleww
coleww / gist:9438486
Created March 8, 2014 20:38
pixel array wrapper for haxing the canvas pixels
//dealing with the pixel data from the canvas is a pain
//gotta multiply everything by four everywhere all the time
//made an object to wrap up all that badness
//a "pixel" is a 4 element array. 0 => R, 1 => G, 2 => B, 3 => A
var PixelArray = root.PixelArray = function(ctx, w, h){
this._pixels = ctx.getImageData(0, 0, w, h).data;
this.w = w;
this.h = h;
this.numPixels = this._pixels.length / 4;
@coleww
coleww / drums.js
Created March 29, 2014 20:42
probabilistic web audio drum machine
var samples = {
kick: new Wad({source: '/samples/kick.wav'}),
chh: new Wad({source: '/samples/chh.wav'}),
snare: new Wad({source: '/samples/snare.wav'}),
ohh: new Wad({source: '/samples/ohh.wav'}),
cym: new Wad({source: '/samples/cym.wav'}),
shkr: new Wad({source: '/samples/shkr.wav'}),
ltom: new Wad({source: '/samples/ltom.wav'}),
mtom: new Wad({source: '/samples/mtom.wav'}),
htom: new Wad({source: '/samples/htom.wav'}),
@coleww
coleww / gist:10149906
Last active August 29, 2015 13:58
nothing but script tags
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
$(function(){
$("<title>").text("JAVASCRIPT PARTY").appendTo($("head"));
$("<div>").addClass("container").css({
"margin": "25px",
"width": "500px",
"border": "1px black solid",
"padding": "15px",
@coleww
coleww / gist:11376678
Created April 28, 2014 16:14
as an agile scrum developer...
i would like to be issued a ticket,
and then click on a link,
which opens related files in sublime text,
and also opens related comps,
and opens a hipchat private message with the related lead,
and pulls from develop
and checks out a new branch named with my initials and part of the issue title,
@coleww
coleww / gist:61bd87e71ee2d40b2db7
Created May 27, 2014 23:44
net art project # 7

buy large quantity of branded consumer goods that are branded with cartoon mascots or somesuch advertising atrocities

  1. cheez its
  2. kool aid
  3. cheetos
  4. other stuff
  5. things

acquire a color printer.

# GIT THEORY
* git status is modified to append an index before each filename
cole@machine:~/PROJECTS/gtr-bf$ gs
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# 0 - TEST.MD
@coleww
coleww / gist:79c9764593ff00cefde1
Created June 2, 2014 23:42
no login social network
https://panopticlick.eff.org/
instead of username/pass concatenate all user agent data together and hash it. users with identical (and i mean identical) machines/environments will have the same "account".
ALTERNATIVELY: use the uniqueness of this string to institute some kind of limit. a game you can only play once. etc. (play, building things until you get cashed, new player steps in, etc.)
OH ALSO: a game where you control like 100 copies of yourself. multiple man: the game?
@coleww
coleww / gist:9561fb22a4cf7888a3a5
Last active August 29, 2015 14:02
render html in sql
CREATE OR REPLACE FUNCTION render (table_name string, action string, ids string)
RETURNS string AS $rendered_template$
BEGIN
declare
temp_temp string;
rendered_template string;
SELECT
db_views.template AS template, db_views.variables AS variables
FROM
db_views