Skip to content

Instantly share code, notes, and snippets.

View kalleth's full-sized avatar

Tom Russell kalleth

View GitHub Profile

Sony Bravia HTTP API

The sony bravia has a HTTP API interacted with using a Pre-Shared key. There's a more complex auth flow but I've not described it here.

There wasn't any documentation, so I've written some. If you're a TV integrator don't read this, you'll laugh. I'm probably just getting confused by UPnP.

Disclaimer: I've only tested this on my TV, which is a KDL-50W829B. Your TV might not have all of the services; see Available services section for how to discover what your TV supports.

@kalleth
kalleth / example_failing_spec.rb
Created December 4, 2013 22:22
shoulda-matchers attempting to create errors container
require 'spec_helper'
class FakeOrder
include ActiveModel::Validations
attr_accessor :site_ids, :user_id
validate :validate_at_least_one_site_chosen
validates_presence_of :user_id
def validate_at_least_one_site_chosen
errors.add(:site, "please choose at least one site")
@kalleth
kalleth / migrate_db.rb
Created November 29, 2013 17:41
Migrate the viewr database!
require 'rubygems'
require 'data_mapper'
require 'nokogiri'
# Connect to database
DataMapper.setup(:default, 'mysql://root@localhost/mpuk')
class Event
include DataMapper::Resource
property :id, Serial
@kalleth
kalleth / f1pitradio-twitterbot.rb
Created September 9, 2013 10:01
Twitter bot to relay a twitter account to IRC
#!/usr/bin/env ruby
require 'cinch'
require 'tweetstream'
require 'pry'
require 'pp'
FOLLOWED_USERS = [595112123,710713526,1695958922] # Array of twitter ID's to follow
TweetStream.configure do |config|
config.consumer_key = 'YOUR-CONSUMER-KEY'
# my controller
def create
@uid = Uid.find_by(number: uid_params[:number])
if @uid
update
else
@uid = Uid.new(uid_params)
if @uid.save
puts "Uid is #{@uid.inspect}"
class Duck
def get_angry_tubbo
self.quack
end
def get_angry_everyone_else_in_the_world
quack
end
def quack
@kalleth
kalleth / idea.rb
Created January 15, 2013 11:37
valids
field :name
accessible
validates :presence do
message "please provide a name"
end
end
field :email
accessible
validates :format do
@kalleth
kalleth / checking.rb
Created November 20, 2012 11:14
Refactor attempt following SRP
def do_bulk_creation # Controller action called from request
prize = Prize.find_by_id(params[:code][:prize_id])
codes = params[:code][:codes].split("\r\n").each{ |c| c.strip }
if bulk_creation_valid?(prize, codes)
perform_bulk_creation(prize, codes)
else
set_bulk_creation_error(prize, codes)
@bulk = Code.new(params[:code])
render :action => :bulk_create
end
@kalleth
kalleth / classes.rb
Created October 20, 2012 00:11
hmm, polymorphism?
class DataCenter < ActiveRecord::Base
# has configuration_type, configuration_id attributes
def config
configuration_type.constantize.find(configuration_id)
end
def config=(config)
configuration_type = config.class.name
configuration_id = config.id
end
@kalleth
kalleth / usage.rb
Created July 19, 2012 19:41
getting attrs
class MyClass
attr_accessor :at1, :at2, :at3
def initialize
@at1 = "one"
@at2 = "two"
@at3 = "three"
end