Skip to content

Instantly share code, notes, and snippets.

View jimsynz's full-sized avatar
💜

James Harton jimsynz

💜
View GitHub Profile
PostsController < ApplicationController
def show
@post = Post.find_by_slug(params[:id])
end
end
@jimsynz
jimsynz / example_schema.rb
Created October 10, 2010 20:40
Patch ActionDispatch to build routes based on the STI base class. http://sociable.co.nz/post/1286186984/patch-rails3-sti
# app/models/meats.rb
class Meat < ActiveRecord::Base
end
# app/models/bacon.rb
class Bacon < Meat
end
# app/models/chunky_bacon.rb
class ChunkyBacon < Bacon
@jimsynz
jimsynz / production.rb
Created November 3, 2010 22:50
snipped of a chef recipe.
include_recipe 'iptables'
iptables_rule 'ssh_in'
iptables_rule 'http_in'
iptables_rule 'https_in'
iptables_rule 'mongo_in' do
only_if { node[:mongo][:replica_set][:enabled] }
variables :rs_members => search(:node, "role:mongo_#{node[:mongo][:replica_set][:name]}")
end
@jimsynz
jimsynz / rebuild.rb
Created November 4, 2010 23:01
Rebuild static HAML and SASS files as changes are saved.
require 'rubygems'
require 'fssm'
monitor = FSSM::Monitor.new
monitor.path File.dirname(__FILE__) do
update do |base,relative|
# Why are they not strings?!?
base = base.to_s
relative = relative.to_s
extension = relative.split('.').last
@jimsynz
jimsynz / Daemonfile.rb
Created November 7, 2010 21:06
Daemonfile for running Delayed::Worker instances.
# How often daemonizer's monitor process
# checks the status of workers.
poll_period 5
pool :delayed_workers do
# Attempt to intuit the number of CPU cores on this machine and start
# a corresponding number of workers. Should work on any modern Linux
# (>= 2.6 kernel).
if File.exist? "/sys/devices/system/cpu/online"
@jimsynz
jimsynz / config.ru
Created November 25, 2010 20:48
Patch for Mongo::GridIO to respond to each as required by the Rack API.
# Patch Mongo::GridIO to contain an each method.
require File.join File.dirname(__FILE__), 'lib/kimono/grid_io'
Mongo::GridIO.send(:include, Kimono::GridIO)
# You probably want to implement something a bit smarter than just talking
# to localhost.
database = Mongo::Connection.new.db('kimono_production')
app = proc do |env|
begin
@jimsynz
jimsynz / ledsinewave.c
Created December 25, 2010 10:09
Pulse the LED with a sine wave.
/*
My second sketch: pulse the LED with a sine wave.
*/
const float pi = 3.14159;
int ledPin = 9;
void sinArc(int analogPin, int duration, float arcStart, float arcStop) {
int steps = 255;
@jimsynz
jimsynz / rgb_spectrum.c
Created January 5, 2011 20:59
Arduino sketch to cycle an RGB LED through the colour spectrum.
const int redPin = 11;
const int greenPin = 10;
const int bluePin = 9;
void setup() {
// Start off with the LED off.
setColourRgb(0,0,0);
}
void loop() {
@jimsynz
jimsynz / OutputPin.cpp
Created January 8, 2011 21:48
Example Sketch to fade an LED in and out using dCouple & Aiko.
#include "OutputPin.h"
OutputPin::OutputPin (unsigned int pin) {
// FIXME: What about the Arduino MEGA?!?
switch (pin) {
case 3:
case 5:
case 6:
case 9:
case 10:
#include "Connection.h"
void Connection::is_connected_to(State* state) {
_state = state;
has_new_connection(state);
}
State* Connection::is_connected_to() {
return _state;
}