Skip to content

Instantly share code, notes, and snippets.

View PatrickTulskie's full-sized avatar

Patrick Tulskie PatrickTulskie

View GitHub Profile
#!/usr/bin/env ruby
#
# usage: script/server_restarter
#
# Rails autoloading, while nice in theory, frequently doesn't work. Since Rails 2.3+
# is so fast when completely reloading the server, I wrote this script to listen to the
# given directories, and kill/restart the server when any file is changed.
#
# It's quick, simple, and it reliably reloads your application when changes are made.
#
# An extension to the Hash class to inspect what it is made of
class Hash
def whatami
keys.inject({}) do |hash, key|
hash[key] = case self[key].class.to_s
when "Hash"
self[key].whatami
when "Array"
self[key].map do |item|
before "deploy", :start_serenading
after "deploy", :stop_serenading
desc "Start serenading"
task :start_serenading do
fork {`afplay '/path/to/rollout.mp3'`} rescue nil
end
desc "Stop serenading"
task :stop_serenading do
# Taken and Modified from => \
# http://t-a-w.blogspot.com/2010/05/very-simple-parallelization-with-ruby.html
require "rubygems"
require "active_support"
require 'thread'
def Exception.ignoring_exceptions
begin
yield
require 'rubygems'
require 'eventmachine'
require 'em-websocket'
require 'json'
class Connection
attr_accessor :socket, :user_id
def initialize(socket, user_id)
@socket = socket
upstream unicorn {
server unix:/var/www/example/current/tmp/sockets/unicorn.sock;
}
server {
listen 80;
server_name example.org www.example.org;
access_log /var/log/nginx/example.access.log;
location / {
root /var/www/example/current/public/;
if (-f $request_filename) {
@PatrickTulskie
PatrickTulskie / resque_retry.rb
Created July 25, 2011 19:15 — forked from clemens/resque_retry.rb
Retry failed Resque jobs in Ruby
# inspired by http://ariejan.net/2010/08/23/resque-how-to-requeue-failed-jobs
# retry all failed Resque jobs except the ones that have already been retried
# This is, for instance, useful if you have already retried some jobs via the web interface.
Resque::Failure.count.times do |i|
Resque::Failure.requeue(i) unless Resque::Failure.all(i, 1)['retried_at'].present?
end
# retry all :)
Resque::Failure.count.times do |i|
@PatrickTulskie
PatrickTulskie / caveatPatchor.js
Created July 29, 2011 18:53 — forked from protocool/caveatPatchor.js
Sample Propane caveatPatchor.js file
/**
Sample Propane caveatPatchor.js file based on tmm1's avatar hack.
You'll need at least version 1.1.1 to experiment with this:
http://propaneapp.com/appcast/Propane.1.1.1.zip
Once I'm sure exposing this hack-injection point doesn't cause problems
I'll do an official auto-updating version.
As of version 1.1.1, Propane will load and execute the contents of
@PatrickTulskie
PatrickTulskie / Folder Preferences
Created August 11, 2011 18:47 — forked from chrisyour/Folder Preferences
Show hidden files and hidden folders (except .git) in your TextMate project drawer
# Want to show hidden files and folders in your TextMate project drawer? Simple, just modify the file and folder patterns in TextMate's preferences.
# Instructions:
# Go to TextMate > Preferences...
# Click Advanced
# Select Folder References
# Replace the following:
# File Pattern
require 'benchmark'
require 'pp'
require 'active_record'
require 'sequel'
require 'data_mapper'
@start = Date.parse("2012-12-01")
@end = Date.parse("2012-12-31")
ActiveRecord::Base.establish_connection(adapter: 'mysql2', database: 'escobar_development', cast: false, username: 'root', password: nil, pool: 5, timeout: 5000)