Skip to content

Instantly share code, notes, and snippets.

@stevenklise
stevenklise / parse_csv_to_hubot.rb
Created May 8, 2012 04:06
Save a csv of presentation times names and urls to Hubot's Redis brain
require 'csv'
require 'json'
require 'redis'
require 'uri'
# Open the csv as a csv.
csv = CSV.read('./thesis.csv')
# Outputs as a 2D array but I want a hash to turn in to JSON.
thesisweek = {
@stevenklise
stevenklise / chatlogs_to_file.rb
Created May 13, 2012 05:14
Save chatlogs to file as JSON from Redis
require 'date'
require 'uri'
require 'redis'
require 'json'
# Parse out the parts of the redistogo uri
uri = URI.parse ENV['REDISTOGO_URL']
# Create connection to Redis using the uri info
@redis = Redis.new :host => uri.host, :port => uri.port, :password => uri.password
<span class="n">xoff</span> <span class="o">+=</span> <span class="mf">0.01</span><span class="o">;</span>
<strong> <span class="n">xoff</span> <span class="o">+=</span> <span class="mf">0.01</span><span class="o">;</span></strong>
@stevenklise
stevenklise / post.rb
Created August 20, 2012 21:12
Has n, :through
post '/races/new' do
# params = {"cars" => [ {"car_id" => 1, "duration" => 30}, {"car_id" => 2, "duration" => 40} ] }
race = Race.new
# Assuming that "car_id" is the same as the DB ID
params["cars"].each do |car|
# Here we are making a new "Racing" for each car listed in the params. See that I'm using ":car_id" and not ":car" which I showed you above. In the above ":car" accepted an entire Car model, but it can also accept just the ID of a Car by doing "
race.racings << Racing.new(:car_id => car["car_id"], :duration => car["duration"])
@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"
}
@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 / 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 / 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 / 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 / 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