Skip to content

Instantly share code, notes, and snippets.

View Sutto's full-sized avatar

Darcy Laycock Sutto

View GitHub Profile
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
RVM.use_from_path! File.dirname(File.dirname(__FILE__))
rescue LoadError
# RVM is unavailable at this point.
raise "RVM ruby lib is currently unavailable."
@Sutto
Sutto / capture-output.rb
Created June 2, 2011 01:13
A simple(?) way to capture stderr and stdout without losing them. Not 100% perfect...
require 'tempfile'
class IOMirror
attr_accessor :original_stdout, :original_stderr, :mirror_stdout, :mirror_stderr
def initialize(mirror_stdout, mirror_stderr)
@mirror_stdout = mirror_stdout
@mirror_stderr = mirror_stderr
@sync_mapping = {}
class Decorator
def initialize(decorated)
@decorated = decorated
end
def method_missing(method, *args, &blk)
@decorated.send(method, *args, &blk)
end
require 'parslet'
module SmegHead
module ACL
class Parser < Parslet::Parser
def self.parse(text)
parser = new
parser.parse text
rescue Parslet::ParseFailed => error
@Sutto
Sutto / gist:943752
Created April 27, 2011 05:22
Resque Daemon Controller
#!/usr/bin/env ruby
ENV['RAILS_ENV'] ||= 'development'
require File.expand_path('../../config/environment', __FILE__)
require 'daemon_spawn'
class ResqueWorkerDaemon < DaemonSpawn::Base
def start(args)
@worker = Resque::Worker.new('*') # Specify which queues this worker will process
@Sutto
Sutto / sickbeard-clean-library.rb
Created April 6, 2011 10:20
Moved a folder? Clean your sickbeard library...
require 'rubygems'
require 'sequel'
database = Sequel.connect('sqlite://sickbeard.db')
database[:tv_episodes].select(:location, :episode_id).exclude(:location => "").each do |show|
if !File.file?(show[:location])
database[:tv_episodes].filter(:episode_id => show[:episode_id]).delete
end
end
diff --git a/lib/cnet.tcl b/lib/cnet.tcl
index 77f3da1..3adf62c 100644
--- a/lib/cnet.tcl
+++ b/lib/cnet.tcl
@@ -129,7 +129,7 @@ proc initworld {topology bg mapx mapy gflag maxspeed procs
-background $framebg \
-activebackground $canvasbg
- set m [menu .cnet.mb.cnet -background $framebg -tearoff 0]
+ set m [menu .cnet.mb.cnet -tearoff 0]
def diff(a, b, file = "current.diff")
require 'rspec/expectations/differ'
differ = RSpec::Expectations::Differ.new
diff = differ.diff_as_object(a, b)
File.open(file, "w+") { |f| f.write diff }
system "mate", file
end
gemset_under_alias() {
local gemset="$1"
local alias_name="$2"
local fallback_ruby="$3"
local expanded_alias="$(rvm alias show "$alias_name" 2>/dev/null)"
if [[ -n "$expanded_alias" ]]; then
rvm "$alias_name@$gemset" --create
else
rvm "$fallback_ruby@$gemset" --create
#!/bin/bash
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs $network $syslog nginx
# Required-Stop: $local_fs $remote_fs $network $syslog nginx
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts unicorn
# Description: starts unicorn web app servers