Skip to content

Instantly share code, notes, and snippets.

View stve's full-sized avatar

Steve Agalloco stve

View GitHub Profile
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
if forked
# We're in smart spawning mode.
Member.connection.reconnect!
Rails.cache.instance_variable_get(:@cache).quit if Rails.cache.class == ActiveSupport::Cache::LibmemcachedStore
else
# We're in conservative spawning mode. We don't need to do anything.
end
end
namespace :cache do
namespace :fragment do
desc 'Manually remove all fragment caches'
task :delete => :environment do
ActionController::Base.cache_store.clear
end
end
end
@stve
stve / git-track
Created June 16, 2010 04:58 — forked from jamie/git-track
#!/usr/bin/env ruby
# Sets up remote tracking if you forgot to --track a branch,
# or if you're setting up a new branch.
# Save in ~/bin/ or somewhere else on your path.
# Usage:
# git track [[remote] branch]
# remote defaults to 'origin'
# branch defaults to the name of the current local branch
if request.accept.include?('application/json')
content_type :json
else
content_type :text
end
# MongoMapper "embedded document delete" plugin
# By Peter Cooper
#
# Got embedded documents you want to delete? You can delete them as if the
# embedded document collection were an array, but then there's no way to get
# a callback (as far as I could tell). This plugin gives you a call back
# (if you want it) and gives a nicer syntax to deleting embedded docs.
#
# Example:
#
class Foo
plugin MongoMapper::Plugins::IdentityMap
end
Or you can add to all documents like this:
module IdentityMapAddition
def self.included(model)
model.plugin MongoMapper::Plugins::IdentityMap
end
.DS_Store
*.csv
*.pdf
@stve
stve / xlsx2csv
Created May 20, 2010 14:11
Convert an xlsx file to a csv
#!/usr/bin/env ruby
require 'rubygems'
require 'fastercsv'
require 'roo'
if ARGV.size >= 1
file = ARGV.first
if file && File.exists?(file) && File.extname(file) == '.xlsx'
@stve
stve / gist:375314
Created April 22, 2010 14:45 — forked from assaf/gist:291329
require "resque"
require "resque/failure/multiple"
require "resque/failure/redis"
# Configure Resque connection from config/redis.yml. This file should look
# something like:
# development: localhost:6379
# test: localhost:6379:15
# production: localhost:6379
Resque.redis = YAML.load_file(Rails.root + 'config/redis.yml')[Rails.env]
@stve
stve / gist:301188
Created February 11, 2010 03:46 — forked from tpitale/gist:162954
#! /bin/sh
### BEGIN INIT INFO
# Provides: mongodb
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the mongodb data-store
# Description: starts mongodb using start-stop-daemon