Skip to content

Instantly share code, notes, and snippets.

View nixterrimus's full-sized avatar
💭
End of line

[Gone] nixterrimus

💭
End of line
View GitHub Profile
// Javascipt
var watchers = {};
var activeWatchers = {};
var Timer = process.binding('timer').Timer;
@nixterrimus
nixterrimus / gist:1234258
Created September 22, 2011 07:46
HTTP Basic Authentication
class PagesController < ApplicationController
before_filter :authenticate
def secret_page
@time = Time.now
end
protected

todo.rb

todo.rb is a dead simple command line todo list manager written in Ruby by Nick Rowe. It was originally written for Codebrawl. It's now a slightly more filled out gem (with tests!). The todo.rb gem is on Github.

Making it Go - A Simple Tutorial

todo.rb is simple, first lets add some items to our list

./todo.rb buy tomato seeds

@nixterrimus
nixterrimus / demo.rb
Created January 16, 2013 18:55
Defining Methods on the top level main object in Ruby adds them as private methods to Object
# The semi-magic ability to define a method on the top level
# main object and have it be available as a private method to
# all object
# ref: http://stackoverflow.com/a/917842
def magical_mystery(thing)
"The Magical Mystery #{thing} is waiting to take you away"
end
class Rabbit
@nixterrimus
nixterrimus / sample_adapter.rb
Created January 17, 2013 06:18
A spirit adapter exposes a very minimal API and leaves the implementation up to the programmer.
module Adapter
class SampleAdapter
def set_current_state(params = {})
# update the world to looks like what's passed in params
nil
end
def current_state(device = nil)
device.update_attributes({}) if device
@nixterrimus
nixterrimus / arduino_adapter.rb
Last active December 11, 2015 05:48
A spirit Arduino blinky adapter
require 'dino'
class ArduinoBlinky
attr_accessor :led, :current_state
# implements :light
def initialize
board = Dino::Board.new(Dino::TxRx.new)
@nixterrimus
nixterrimus / persistance_sketch.rb
Created January 22, 2013 06:29
On Persisting devices. I don't think it makes sense for devices to persist themselves. Does it make sense to write a persistance object that deals with saving and loading?
DevicePersistanceThing
def self.load(target_uuid)
# Get associated associated adapter, ask AdapterPersistanceThing
# attributes = query persistance store for uuid
# Setup Device with attributes & adapter
# return device
end
def self.save(device)
# Serialize device
@nixterrimus
nixterrimus / adapter.rb
Last active December 11, 2015 12:48
My latest take on what a spirit adapter will look like
class HueAdapter < Spirit::Adapter::Base
name "Philips Hue"
author "Nick Rowe"
implements :colorable_light, :dimmable_light
require_user_setup :true
user_settings do
@nixterrimus
nixterrimus / adapter_again.rb
Created January 25, 2013 05:11
Adapter, again
class Adapter::HueAdapter < Adapter::Base
creator "Nick Rowe"
adapts_to "Philips Hue Lighting System"
website "http://github.com/nixterrimus/hue-spirit-adapter"
implements :light
requires_setup true
module Device::Abilities::Switchable
extend ActiveSupport::Concern
include Toy::Object
included do
attribute :role, String, :default => 'guest'
end
end