Skip to content

Instantly share code, notes, and snippets.

Being good to others

Evan Walsh evanwalsh

Being good to others
View GitHub Profile
evanwalsh / imgur.rb
Created Aug 21, 2012
Download an gallery with Ruby and Nokogiri
View imgur.rb
#!/usr/bin/env ruby
# Download galleries easily
# Requirements:
# gem install nokogiri
# Usage:
# ruby imgur.rb [url of gallery] [directory to download into] [namespace for files]
evanwalsh / meta_tag_helper.rb
Created Aug 12, 2012
Meta tag helper for Rails
View meta_tag_helper.rb
# Accepts arguments like:
# meta_tag :warning, "HC SVNT DRACONES"
# or
# meta_tag charset: "utf-8"
def meta_tag *options
if ( {|o| o.is_a?(String) || o.is_a?(Symbol) }.count == options.count) && (options.count == 2)
tag :meta, name: options.first, content: options.last
tag :meta, *options
evanwalsh / app--helpers--application_helper.rb
Created May 4, 2012 — forked from nickhoffman/app--helpers--application_helper.rb
pjax is awesome, but causes code within #content_for not to be rendered. Here's a solution.
View app--helpers--application_helper.rb
module ApplicationHelper
def content_for_or_pjax(name, &block)
request.headers['X-PJAX'] ? capture(&block) : content_for(name, &block)
evanwalsh / gist:2552100
Created Apr 29, 2012 — forked from joelmoss/gist:2470666
Capistrano recipe for Puma start/stop/restarts
View gist:2552100
set :shared_children, shared_children << 'tmp/sockets'
namespace :deploy do
desc "Start the application"
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && RAILS_ENV=#{stage} bundle exec puma -b 'unix://#{shared_path}/sockets/puma.sock' -S #{shared_path}/sockets/puma.state --control 'unix://#{shared_path}/sockets/pumactl.sock' >> #{shared_path}/log/puma-#{stage}.log 2>&1 &", :pty => false
desc "Stop the application"
task :stop, :roles => :app, :except => { :no_release => true } do
evanwalsh / levenshtein.rb
Created Apr 20, 2012
Levenshtein distance
View levenshtein.rb
class String
def levenshtein(other, ins=2, del=2, sub=1)
# ins, del, sub are weighted costs
return nil if self.nil?
return nil if other.nil?
dm = [] # distance matrix
evanwalsh / gist:2165317
Created Mar 22, 2012 — forked from jrochkind/gist:2161449
A Capistrano Rails Guide
View gist:2165317

A Capistrano Rails Guide

by Jonathan Rochkind,

why cap?

Capistrano automates pushing out a new version of your application to a deployment location.

I've been writing and deploying Rails apps for a while, but I avoided using Capistrano until recently. I've got a pretty simple one-host deployment, and even though everyone said Capistrano was great, every time I tried to get started I just got snowed under not being able to figure out exactly what I wanted to do, and figured I wasn't having that much trouble doing it "manually".

evanwalsh / gist:1405271
Created Nov 29, 2011
Print from a non-Postscript Ricoh printer on a Mac
View gist:1405271
Download the following in this order and install from here:
Ghostscript for Mac OS X 10.3.x (Panther) - Mac OS X 10.6.x (Snow Leopard)
Foomatic-RIP for Mac OS X 10.3.x (Panther) - Mac OS X 10.6.x (Snow Leopard)
pxlmono 1.6 for Mac OS X 10.3.x (Panther) - Mac OS X 10.6.x (Snow Leopard)
Once installed add your printer and use the following driver Ricoh Aficio MX C2500 PXL and you should have a fully working colour printer:
evanwalsh / gist:1332546
Created Nov 2, 2011
database_cleaner with MiniTest::Spec
View gist:1332546
require 'database_cleaner'
DatabaseCleaner.strategy = :truncation
class MiniTest::Spec
before :each do
View posts_controller_spec.rb
require 'spec_helper'
describe PostsController do
before do
@post = Fabricate :post
describe "GET index", type: :request do
before do
View spec_helper.rb
require 'spork'
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
# Hey, Mongoid! Don't cache that class!
require "rails/mongoid"
Spork.trap_class_method(Rails::Mongoid, :load_models)