Skip to content

Instantly share code, notes, and snippets.

@pch
pch / Gemfile
Last active August 29, 2015 14:04
# rspec
group :test do
gem 'rspec-rails'
gem 'launchy'
gem 'capybara'
gem 'webrat'
gem 'database_cleaner'
gem 'email_spec'
gem 'factory_girl_rails'
end
@pch
pch / discipline
Created February 13, 2014 11:49
Tricking myself into writing.
#!/usr/bin/env ruby
#
# I use the following script to trick myself into writing every day.
#
# All it does is create a directory for the current month (YYYY/MM),
# create an empty markdown file for today and annoy the hell out of
# me until I put something in that file.
#
# I run the script with GeekTool every 30 minutes:
# http://projects.tynsoe.org/en/geektool/
@pch
pch / assert_queries.rb
Last active October 29, 2022 21:13
assert_queries - rails 4
# Assertion for checking the number of queries executed within the &block
def assert_queries(num = 1, &block)
queries = []
callback = lambda { |name, start, finish, id, payload|
queries << payload[:sql] if payload[:sql] =~ /^SELECT|UPDATE|INSERT/
}
ActiveSupport::Notifications.subscribed(callback, "sql.active_record", &block)
ensure
assert_equal num, queries.size, "#{queries.size} instead of #{num} queries were executed.#{queries.size == 0 ? '' : "\nQueries:\n#{queries.join("\n")}"}"
@pch
pch / git-sync
Last active August 30, 2021 08:57
Git sync - light version
#!/bin/sh
git_branch() {
echo $(git symbolic-ref HEAD 2>/dev/null | awk -F/ {'print $NF'})
}
git_dirty() {
st=$(git status 2>/dev/null | tail -n 1)
if [[ $st == "" ]]
then
@pch
pch / trimws.sh
Last active May 17, 2016 09:31
Nukes all trailing whitespace in the current project (rails specific).
find . -not \( -name .git -prune -o -name images -prune -o -name GeoLiteCity.dat -prune \) -type f -print0 | xargs -0 perl -pi -e 's/ +$//'
require 'net/http'
out = `arp-scan -lq`
macs =
out.split("\n").map do |line|
if line =~ /([0-9A-F][0-9A-F :]{16})/i
puts $1
$1.split(' ').join(':').upcase
end
end.compact.join(',')
@pch
pch / gist:1322006
Created October 28, 2011 10:01
Spotify

How to use Spotify in any country

If you can put up with ads, you can easily trick Spotify and sign up for an account, even if you're not in one of the supported countries. You'll need:

  • A Facebook account
  • SSH access to a server based in one of the supported countries (US, UK, whatevs).

First, set up an SSH tunnel, as described here: http://paulstamatiou.com/how-to-surf-securely-with-ssh-tunnel

# 1
Foo.bar(
:one => 1,
:two => 2
)
# 2
Foo.bar(
:one => 1,
:two => 2)
module Devise
module Controllers
module ScopedViews
protected
# Monkey path for generating proper templates path when dealing with
# namespaced resources and custom views.
def render_with_scope(action, options={})
controller_name = options.delete(:controller) || self.controller_name
if self.class.scoped_views?
@pch
pch / watermark.rb
Created January 18, 2011 13:43
Paperclip Watermark processor
class User
has_attached_file :photo,
:processors => [:watermark],
:styles => {
:medium => {
:geometry => "300x300>",
:watermark_path => "#{Rails.root}/public/images/watermark.png"
},
:thumb => "100x100>",
}