Skip to content

Instantly share code, notes, and snippets.

@karmi
karmi / resque_workers.rake
Created May 11, 2010 16:45
Our Rake task for running multiple Resque workers in production
namespace :queues do
desc "Run Resque workers with options and job classes loaded"
# Run with & appended to daemonize
task :workers => :environment do
def pid_directory
Rails.root.join('tmp', 'pids')
end
@karmi
karmi / post-receive-deploy.rb
Created June 17, 2010 13:21
Example script to deploy a Rails application via Git post-receive hook
#!/usr/bin/env ruby
# Example script to deploy a Rails application via Git post-receive hook
#
# INSTALL
#
# $ curl http://gist.github.com/442106.txt -o post-receive
# $ mv post-receive path/to/to/your/repo.git/hooks/post-receive
# $ chmod +x post-receive
# Abstract classes, const_get etc examples for a dev friend
class String
# http://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/string/inflections.rb#L44-49
def camelize
self.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
end
end
module MyParsers
@peplin
peplin / recipe.rb
Created July 10, 2010 01:30
S3 File Resource for Chef
# Source accepts the protocol s3:// with the host as the bucket
# access_key_id and secret_access_key are just that
s3_file "/var/bulk/the_file.tar.gz" do
source "s3://your.bucket/the_file.tar.gz"
access_key_id your_key
secret_access_key your_secret
owner "root"
group "root"
mode 0644
end
@karmi
karmi / git-hosting-apache.conf
Created July 21, 2010 07:43
Configuration for hosting Git repositories with Apache 2.x
# ----------------------------------------------------------
# Configuration for hosting Git repositories with Apache 2.x
# ----------------------------------------------------------
#
# This setup provides "dual URLS", where URL like <http://git.example.com/my_repository.git>
# loads Gitweb in the browser and the same URL can be used in commands like `git clone` and `git remote add`.
# It was compiled from some sources on the internet and further customized/tuned.
#
# Please see documentation for:
#
@karmi
karmi / workers.rake
Created July 22, 2010 15:58
Rake taks to launch multiple Resque workers in development/production with simple management included
# Rake task to launch multiple Resque workers in development/production with simple management included
require 'resque/tasks' # Require Resque tasks
namespace :workers do
# = $ rake workers:start
#
# Launch multiple Resque workers with the Rails environment loaded,
# so they have access to your models, etc.
@karmi
karmi / mac_os_setup.sh
Created December 19, 2010 13:43
Installation Instructions For Setting Up A Clean Mac OS X System
# =====================================================
# Installation instructions for a clean Mac OS X system
# =====================================================
#
# <https://gist.github.com/747336>
#
# Keep only `.ssh` and `.profile.local` files from backup
# + Clean up Apple Ruby
@karmi
karmi / slingshot.rb
Created February 6, 2011 14:17
Sketch of a Ruby API for ElasticSearch [http://elasticsearch.com]
# Sketch of a Ruby API for ElasticSearch [http://elasticsearch.com]
require 'rubygems'
require 'curb'
require 'rest_client'
require 'yajl/json_gem'
module Slingshot
def http
@karmi
karmi / collection.rb
Created March 8, 2011 11:59
Module which allows to use a proxy class for wrapping collections of all sorts.
# = Collection
#
# Module which allows to use a proxy class for wrapping collections of all sorts.
#
# Let's take a collection of articles, for example (see also the test suite below).
#
# The collection item class could look like this:
#
# class Article
# attr_reader :title
@benjchristensen
benjchristensen / index.html
Created August 16, 2011 03:21
Animated Line Graphs / Sparklines using SVG Path and d3.js
<html>
<head>
<title>Animated Sparkline using SVG Path and d3.js</title>
<script src="http://mbostock.github.com/d3/d3.v2.js"></script>
<style>
/* tell the SVG path to be a thin blue line without any area fill */
path {
stroke: steelblue;
stroke-width: 1;
fill: none;