Skip to content

Instantly share code, notes, and snippets.

@rjhornsby
rjhornsby / Song.rb
Last active August 29, 2015 14:23
Ruby Song class
class Song
# TODO: enforce limits on the input
attr_accessor :title
attr_accessor :artist
attr_accessor :album
attr_accessor :remarks
attr_accessor :url
attr_accessor :error
@rjhornsby
rjhornsby / songtest.rb
Created June 16, 2015 19:51
Song serialization test script
#!/usr/bin/ruby
require 'pp'
require 'json'
require_relative 'plugins/song'
song1 = Song.new
song1.title = 'New Title'
song1.artist = 'Artist 1'
@rjhornsby
rjhornsby / gfnb_version.sh
Last active March 5, 2016 14:15
Shell script to notify if the GFNB software version changes
#!/bin/bash
# We will try to determine your GFNB address automatically by using
# your system's gateway address.
#
# If that doesn't work, or you want to override the detected
# value, uncomment the following line and set the value you want
#
# gfnb_ip=192.168.1.1
class Track < ActiveRecord::Base
self.table_name = 'SONGLIST'
has_one :supplemental
end
class Supplemental < ActiveRecord::Base
self.table_name = 'amazon_metadata'
belongs_to :track
end
@rjhornsby
rjhornsby / gfnb_temperature.sh
Last active September 6, 2015 05:10
Output the GFNB temperature readings
#!/bin/bash
# Set this to your router's address #
gfnb_ip=192.168.2.1
# Don't change anything below this line #
echo -n "$(date) "
curl -s "http://$gfnb_ip/content.json?checksum=0&_=0" | ruby -rjson -e 'puts JSON.parse(STDIN.read)["temperature"]'
#!/bin/bash
echo -n "[$(date)] "
result=$(/usr/bin/time -p curl -s http://google.com 1> /dev/null 2> /tmp/timer)
echo "exit:$? elapsed:$(awk '/^real/ {print $2}' /tmp/timer)"
def to_h
super.merge(
{
:asin => @asin
})
end
def to_json(*a)
{
:json_class => self.class.name,
def to_h
{
:title => title,
:artist => artist,
:album => album,
:remarks => remarks,
:url => url,
:short_url => short_url,
}
end
$ ./shelter.rb
== constructing a dog ==
== constructing an animal ==
Pets rendered as JSON:
[{"json_class":"Dog","data":{"has_fur":true,"color":"black","name":"fido","bark":"loud"}}]
=== Recovering lost pets from the evil JSON Deville ===
Calling Dog::json_create
{"json_class"=>"Dog",
"data"=>{"has_fur"=>true, "color"=>"black", "name"=>"fido", "bark"=>"loud"}}
== constructing a dog ==
== constructing an animal ==
Pets rendered as JSON:
[{"json_class":"Dog","data":{"has_fur":true,"color":"black","name":"fido","bark":"loud"}}]
=== Recovering lost pets from the evil JSON Deville ===
Calling Dog::json_create
{"json_class"=>"Dog",
"data"=>{"has_fur"=>true, "color"=>"black", "name"=>"fido", "bark"=>"loud"}}
== constructing a dog ==