Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

PVector[] vectors = {leftHand, rightHand, leftElbow, rightElbow, leftShoulder, rightShoulder};
// returns m and b as 0 and 1 of an array respectively.
float[] fits = bestFit(vectors);
// this value is floating all over the place
float r2 = rsquare(vectors, fits[0], fits[1]);
@stevenklise
stevenklise / app.rb
Created April 18, 2013 19:34
Using `irb` to connect to a Sinatra app or DataMapper connection
# require basic libraries
source 'https://rubygems.org'
require 'rubygems'
require 'sinatra'
require 'data_mapper'
# require DataMapper adapter, in this case we'll use Postgres
require 'dm-postgres-adapter'
DataMapper.setup(:default, ENV['DATABASE_URL'])
@stevenklise
stevenklise / index.html
Created January 30, 2013 18:35
Getting started with processing.js http://jsfiddle.net/mzB4h/
<html>
<head>
<script src="http://cloud.github.com/downloads/processing-js/processing-js/processing-1.4.1.js"></script>
<script>
function sketchProc(processing) {
// Override draw function, by default it will be called 60 times per second
// void draw() { ... }
processing.draw = function() {
// determine center and max clock arm length
var centerX = processing.width / 2, centerY = processing.height / 2;
@stevenklise
stevenklise / gzip_test.js
Last active December 11, 2015 10:29
It turns out this was easy, but it was hard to find complete documentation. Here is how to make a request with request (http://npmjs.org/package/request) and unpack a gzipped body.
var request = require('request');
var zlib = require('zlib');
var url = "http://api.stackexchange.com/2.1/search?order=desc&sort=activity&intitle=backbone&site=stackoverflow";
request({
encoding: null, // this keeps the body as a buffer and not a string
url: url,
headers: { 'accept-encoding': 'gzip,deflate' }
}, function (err, res, body) {
@stevenklise
stevenklise / dogs.rb
Created January 18, 2013 19:35
i _really_ like dogs
50.times do
%x(curl --data "vote=dog" http://www.therehasneverbeenanythinglikethis.com/vote)
sleep (2.0)
end
@stevenklise
stevenklise / app.js
Last active December 10, 2015 20:38
How to include Ecstatic https://github.com/jesusabdullah/node-ecstatic with http.createServer() and other routes.
var http = require('http');
// Set up ecstatic to read from the root folder of this app.
var ecstatic = require('ecstatic')(__dirname);
var matchRoutes = function (req, res) {
console.log('Request: '+ req.method + ' ' + req.url)
// Match the main route "/"
if (req.url === "/" ) {
res.writeHead(200, {'Content-Type': 'text/plain'});
@stevenklise
stevenklise / gist:4033284
Created November 7, 2012 18:05 — forked from atduskgreg/gist:1258552
new_sinatra_app.rb
#!/usr/bin/env ruby
require 'fileutils'
install_root = File.expand_path(File.dirname(__FILE__))
if !ARGV[0]
puts "ERROR: You must supply the name of the app you want to create. Like this:"
puts "./new_sinatra_app my_app"
exit 1
@stevenklise
stevenklise / array_of_objects.pde
Created October 18, 2012 18:37
A simple example of setting and getting objects into an array
class Point {
int year;
int population;
float rateOfChange;
Point(int _year, int _population){
year = _year;
population = _population;
}
@stevenklise
stevenklise / .gitignore_global
Created September 25, 2012 02:33
Gitconfig and gitignore
# http://help.github.com/ignore-files/
# git config --global core.excludesfile ~/.gitignore_global
# Ruby Config #
###############
.sass-cache/
.bundle/
# Compiled source #
###################
@stevenklise
stevenklise / package.json
Created September 13, 2012 22:47
Simple static file serving with Node.js
{
"name": "node-static-test",
"version": "0.0.1",
"engines": {
"node": "0.8.x"
},
"dependencies" : {
"http": "latest",
"node-static": "latest"
}