Skip to content

Instantly share code, notes, and snippets.

View airblade's full-sized avatar

Andy Stewart airblade

View GitHub Profile
@balexand
balexand / xip_hack.rb
Created June 8, 2012 06:23
xip.io request hack
if Rails.env.development?
class XipIoMiddleware
def initialize(app)
@app = app
end
def call(env)
%w{HTTP_HOST SERVER_NAME SERVER_ADDR HTTP_X_FORWARDED_HOST}.each do |key|
env[key] = env[key].sub(/myapp\.\d+\.\d+\.\d+\.\d+\.xip\.io/, "myapp.dev") if env[key].present?
end
@jasonm23
jasonm23 / xterm-256color.svg
Last active May 1, 2025 12:22
Xterm 256color mode color chart, organised into sections. (used on Wikipedia/xterm)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@justinko
justinko / Plea.markdown
Created May 30, 2012 19:40
Am I doing it wrong?

Dear Rubyists,

I just lost a contract because of my code in a Rails project.

The specific code in question is related to a "posting a comment" feature. Here are the details:

In this project, "posting a comment" does not simply entail inserting a row into the database. It involves a procedure to yes, insert a row, but also detect its language, check for spam, send emails, and "share" it to Twitter and Facebook. I believe this algorithm should be encapsulated. I do not believe it belongs in a controller or a model. I do not believe Active Record callbacks should be used.

The "senior developer", whom is the stake holder's right hand man, said this:

@roberocity
roberocity / git-deploy.rb
Created May 9, 2012 19:39
Git-based deployment for Sinatra
require 'sinatra/base'
require 'time'
class GitHook < Sinatra::Base
def self.parse_git
# Parse hash and date from the git log command
sha1, date = `git log HEAD~1..HEAD --pretty=format:%h^%ci`.strip.split('^')
set :commit_hash, sha1
set :commit_date, Time.parse(date)
@rtomayko
rtomayko / gist:2601550
Created May 5, 2012 10:58
Open beautiful git-scm.com manual pages w/ git help -w
# The new git-scm.com site includes man pages designed for pleasant viewing in a web browser:
#
# http://git-scm.com/docs
#
# The commands below can be used to configure git to open these pages when
# using `git help -w <command>' from the command line. Just enter the config
# commands in your shell to modify your ~/.gitconfig file.
# Create a new browser command and configure help -w to use it.
git config --global browser.gitscm.cmd "/bin/sh -c 'open http://git-scm.com/docs/\$(basename \$1 .html)' --"
@ryanb
ryanb / chef_solo_bootstrap.sh
Created April 5, 2012 04:35
Bootstrap Chef Solo
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev libyaml-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
tar -xvzf ruby-1.9.3-p125.tar.gz
cd ruby-1.9.3-p125/
./configure --prefix=/usr/local
make
make install
@cookrn
cookrn / links.md
Created March 20, 2012 19:51
How to Create and Apply a Patch w/ Git Across Similar Repositories
@ahoward
ahoward / silenceable_logger.rb
Created March 14, 2012 14:33
config/initializers/silenceable_logger.rb
# inspired by : http://dennisreimann.de/blog/silencing-the-rails-log-on-a-per-action-basis/
#
# file: ./config/initializers/silenceable_logger.rb
#
# then, in some crazy js polling action use
#
# ajax('/poll?silence=logger')
#
Rails::Rack::Logger.class_eval do
def call_with_silenced_logger(env)
@mudge
mudge / alternate_method_controller.rb
Created March 9, 2012 17:31
Are filters abused in Rails?
class MyController < ApplicationController
def show
@model = load_model
end
def edit
@model = load_model
end
private
class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private