Skip to content

Instantly share code, notes, and snippets.

Tom Russell kalleth

Block or report user

Report or block kalleth

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View sony_bravia.md

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.

View prize_draw.rb
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
matcher for table rows containing
View table_matcher.rb
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 Dec 24, 2014
Tag remote in capistrano
View deploy.rb
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 Jul 1, 2014
delegation_chain for SimpleDelegator objects to allow easy inspection of their delegation chain
View simple_delegator_delegation_chain.rb
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 Dec 4, 2013
shoulda-matchers attempting to create errors container
View example_failing_spec.rb
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 Nov 29, 2013
Migrate the viewr database!
View migrate_db.rb
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 Sep 9, 2013
Twitter bot to relay a twitter account to IRC
View f1pitradio-twitterbot.rb
#!/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'
View controller.rb
# 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}"
View duck.rb
class Duck
def get_angry_tubbo
self.quack
end
def get_angry_everyone_else_in_the_world
quack
end
def quack
You can’t perform that action at this time.