Skip to content

Instantly share code, notes, and snippets.

View JamesHarrison's full-sized avatar

James Harrison JamesHarrison

View GitHub Profile
# Audio monitoring
# Watch and automatically restart:
# * jackd
# * rotter
# * darkice
God.pid_file_directory = "/var/run/god"
God.watch do |w|
w.name = "jackd"
w.group = "audio"
w.interval = 15.seconds
#!/usr/bin/env ruby
# Sets the date and time correctly on the RDS encoder
# This is broadcast as RDS metadata (CT) so should be kept accurate
# The internal clock of the PC running this script should be synchronized with
# a GPS or radio clock or network time server using NTP
require 'net/telnet'
def run_cmd(cmd,arg)
s = ""
rds = Net::Telnet::new("Host" => "localhost", "Port" => 2000, "Telnetmode" => false, "Prompt" => /^\+/n)
rds.cmd("#{cmd}=#{arg}\n"){|c| s << c.gsub("??", "").gsub("+","")}
#!/usr/bin/env ruby
# Example script showing how to extract website content and set RDS parameters
require 'rubygems'
require 'nokogiri'
require 'open-uri'
begin
rt = ""
doc = Nokogiri::HTML(open('http://insanityradio.com/'))
doc.css('#whatson_now .showdesc a').each do |l|
rt = l.content rescue ""
# Load a scope from a parameter
@list_scope = Image.get_scope(params[:scope]) if params[:scope]
if @list_scope and @list_scope[:options] and @list_scope[:selector]
@images = Image.all
@images.selector = @list_scope[:selector]
@images.options = @list_scope[:options]
end
# You get the idea.
class Image
def self.set_scope(description, criteria, params, attribute=:id_number)
opts = criteria.options
selector = criteria.selector
scope_params = {}
scope_params[:controller] = params[:controller]
scope_params[:action] = params[:action]
scope_params[:uploader_id] = params[:uploader_id]
scope_params[:id] = params[:id]
scope_params[:ignore_spoiler_for] = params[:ignore_spoiler_for]
app = Dragonfly[:images]
app.configure_with(:imagemagick)
app.analyser.add :average_intensity do |temp_object|
(`python lib/simple_analyser.py #{temp_object.path}`.gsub("\n","").strip.to_f rescue 0.0)
end
app.processor.add :first_frame_of_gif_as_png do |temp_object|
tempfile = Tempfile.new(['dragonfly','.png'])
tempfile.binmode
tempfile.close
`convert #{temp_object.path}[0] #{tempfile.path}`
rails_root = "/home/insanity/iris"
rails_env = "production"
God.watch do |w|
w.name = "unicorn"
w.interval = 30.seconds # default
# unicorn needs to be run from the rails root
w.start = "cd #{rails_root} && /usr/local/bin/unicorn_rails -c #{rails_root}/config/unicorn.rb -E #{rails_env} -D"
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start unicorn application server
# Description: Starts the IRIS application server on boot
### END INIT INFO
%mlt
- Dir.glob('/home/james/Storage/Videos/FreshersFayre2011/*-1600k.flv').each do |f|
%producer{:id=>"producer_#{f}"}
%property{:name=>'resource'}=f
%playlist{:id=>'playlist0'}
- Dir.glob('/home/james/Storage/Videos/FreshersFayre2011/*-1600k.flv').each do |f|
%entry{:producer=>"producer_#{f}"}/
%tractor{:id=>'playlisttractor'}
%multitrack
%track{:producer=>'playlist0'}
@JamesHarrison
JamesHarrison / twitterstats.rb
Created August 12, 2011 09:18
Twitter streaming API to Graphite bridge. Pushes pure volume stats and some other things. Just playing around.
require "rubygems"
require "bundler/setup"
require "tweetstream"
require "simple-graphite"
class TwitterStats
def initialize
@client = TweetStream::Client.new('username', 'password').on_limit do |disc_count|
puts "WARNING: Got limited, lost #{disc_count.to_s}"
end.on_error do |message|
puts "ERROR: #{message}"