Skip to content

Instantly share code, notes, and snippets.

View sandro's full-sized avatar
☀️
Sharing Goodness

Sandro Turriate sandro

☀️
Sharing Goodness
View GitHub Profile
@sandro
sandro / threaded_httparty.rb
Created August 27, 2011 01:34
Parallel HTTParty requests using threads
require 'rubygems'
require 'httparty'
require 'benchmark'
require 'thread'
class Google
include HTTParty
base_uri 'http://google.com'
def self.benchmark
def update_main_artist
artist = artists.first
if rovi_artist
artist = Artist.create(:name => rovi_artist.name)
end
update_attribute :main_artist_id, artist.id
end
def update_main_artist
@sandro
sandro / gist:1045173
Created June 24, 2011 16:40
Kill a process by grepping for a name
pkill() {
if [ $1 ]; then
kill `ps -ef | grep $1 | grep -v 'grep' | awk '{print $2}'`
fi
}
@sandro
sandro / deploy.rake
Created May 16, 2011 22:55
WIP Whiskey Disk deployment with db backup and lesscss generation
require 'whiskey_disk/rake'
require 'whiskey_disk/helpers'
namespace :deploy do
ENV['to'] ||= 'staging'
def verbose_cmd(cmd)
system %(set -x && #{cmd})
end
#!/usr/bin/env ruby
require 'rubygems'
require 'httparty'
class FakeRestJsonApi
include HTTParty
base_uri 'http://google.com/THIS_IS_A_FAKE_URL'
headers 'Accept' => 'application/json'
default_params :output => 'json'
module ActionDispatch
class ShowExceptions
private
def original_exception(exception)
if registered_original_exception?(exception)
exception.original_exception
else
exception
# Dicking around with various setups
# We can define the custom hooks in the deploy rake task itself because
# rake is still the main interface for deployments - no need for a
# separate whiskey_disk_hooks.rb file
require 'whiskey_disk/rake'
# I don't love the way this turned out but the ideas is that WhiskeyDisk
# provides a command-api to build local and remote commands.
class GemCache < WhiskeyDisk::Command
@sandro
sandro / fabrication_attributes_for_ext.rb
Created July 31, 2010 19:01
Fabricate.attributes_for
Fabricate.class_eval do
def self.attributes_for(name, options={})
fetch_schematic(name).attributes.inject({}) do |hash, attribute|
value = attribute.value.respond_to?(:call) ? attribute.value.call : attribute.value
hash.merge(attribute.name => value)
end.merge(options)
end
private
@sandro
sandro / cached_images_controller.rb
Created July 22, 2010 22:19
Carrierwave file cache on heroku
class CachedImagesController < ApplicationController
def show
path = File.join(ImageUploader.cache_dir, params[:path], params[:name])
extension = File.extname(params[:name])[1..-1]
headers['Cache-Control'] = 'public; max-age=300'
send_data File.read(path), :disposition => 'inline', :type => Mime::Type.lookup_by_extension(extension)
end
end
# Simple test to see how subprocesses handle signals.
# The result is that the terminal sends the INTERRUPT signal to both the
# main process and subprocesses.
# If you use the `kill` command on the main process' pid, subprocesses don't
# respond.
def forking
Signal.trap('INT') { puts "INT Trapped"; exit }
5.times do