Skip to content

Instantly share code, notes, and snippets.

View evanwalsh's full-sized avatar
❤️‍🔥
You make me feel almost human

Evan Walsh evanwalsh

❤️‍🔥
You make me feel almost human
View GitHub Profile
@evanwalsh
evanwalsh / imgur.rb
Created August 21, 2012 00:32
Download an imgur.com gallery with Ruby and Nokogiri
#!/usr/bin/env ruby
# Download imgur.com galleries easily
#
# Requirements:
# gem install nokogiri
#
# Usage:
# ruby imgur.rb [url of gallery] [directory to download into] [namespace for files]
#
@evanwalsh
evanwalsh / meta_tag_helper.rb
Created August 12, 2012 00:45
Meta tag helper for Rails
# Accepts arguments like:
# meta_tag :warning, "HC SVNT DRACONES"
# or
# meta_tag charset: "utf-8"
def meta_tag *options
if (options.select {|o| o.is_a?(String) || o.is_a?(Symbol) }.count == options.count) && (options.count == 2)
tag :meta, name: options.first, content: options.last
else
tag :meta, *options
end
@evanwalsh
evanwalsh / app--helpers--application_helper.rb
Created May 4, 2012 03:46 — 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.
module ApplicationHelper
def content_for_or_pjax(name, &block)
request.headers['X-PJAX'] ? capture(&block) : content_for(name, &block)
end
end
@evanwalsh
evanwalsh / gist:2552100
Created April 29, 2012 17:26 — forked from joelmoss/gist:2470666
Capistrano recipe for Puma start/stop/restarts
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
end
desc "Stop the application"
task :stop, :roles => :app, :except => { :no_release => true } do
@evanwalsh
evanwalsh / levenshtein.rb
Created April 20, 2012 13:27
Levenshtein distance
# http://ruby-snippets.heroku.com/string/levenshtein-distance
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
evanwalsh / gist:2165317
Created March 22, 2012 23:04 — forked from jrochkind/gist:2161449
A Capistrano Rails Guide

A Capistrano Rails Guide

by Jonathan Rochkind, http://bibwild.wordpress.com

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
evanwalsh / gist:1405271
Created November 29, 2011 15:50
Print from a non-Postscript Ricoh printer on a Mac
Download the following in this order and install from here:
http://www.linuxfoundation.org/collaborate/workgroups/openprinting/macosxpxlmono
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
evanwalsh / gist:1332546
Created November 2, 2011 01:06
database_cleaner with MiniTest::Spec
require 'database_cleaner'
DatabaseCleaner.strategy = :truncation
class MiniTest::Spec
before :each do
DatabaseCleaner.clean
end
end
require 'spec_helper'
describe PostsController do
before do
@post = Fabricate :post
end
describe "GET index", type: :request do
before do
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)