Navigation Menu

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.

require 'date'
require 'twitter'
require 'dotenv'
Dotenv.load
class TwitterSearch
def fetch(query)
client.search("#{query} since:#{Date.today}").collect do |tweet|
Tweet.new(tweet)
end
@kalleth
kalleth / table_matcher.rb
Created May 1, 2015 13:58
matcher for table rows containing
require 'rspec/matchers'
module Suite
class Table < Struct.new(:table)
def rows
@rows ||= table.all('tbody tr').map do |tr|
tr.all('td').map(&:text)
end
end
end
@kalleth
kalleth / deploy.rb
Created December 24, 2014 15:00
Tag remote in capistrano
namespace :deploy do
before :restart, :tag do
on roles(:app) do
within "#{deploy_to}/repo" do
execute :git, "tag -f deployed-to-#{fetch(:stage)}"
begin
execute :git, "remote add upstream #{fetch(:repo_url)}"
rescue
# The remote might already exist. We don't care if it does.
end
@kalleth
kalleth / simple_delegator_delegation_chain.rb
Created July 1, 2014 09:57
delegation_chain for SimpleDelegator objects to allow easy inspection of their delegation chain
class SimpleDelegator
def delegation_chain
[self].tap do |output|
object = self
while object.respond_to?("__getobj__")
object = object.__getobj__
output << object
end
end
end
@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