Skip to content

Instantly share code, notes, and snippets.

View benpickles's full-sized avatar
🏎️

Ben Pickles benpickles

🏎️
View GitHub Profile
@benpickles
benpickles / Makefile
Created April 2, 2014 14:19
Update `~/.vim/bundle`s with the power of make
BUNDLES = $(shell ls bundle)
BUNDLE_TARGETS = $(addprefix update_, $(BUNDLES))
list:
@for BUNDLE in $(BUNDLES); do echo $$BUNDLE; done
update: $(BUNDLE_TARGETS)
update_%:
cd bundle/$(*F) && git pull
@benpickles
benpickles / .railsrc
Created March 31, 2015 14:54
My ~/.railsrc Rails defaults
--database=postgresql
--skip-bundle
--skip-javascript
--skip-keeps
--skip-spring
--skip-test-unit
### Keybase proof
I hereby claim:
* I am benpickles on github.
* I am benpickles (https://keybase.io/benpickles) on keybase.
* I have a public key whose fingerprint is D3E2 C490 65FA 7406 95B1 8556 B014 2155 1D63 7BB7
To claim this, I am signing this object:
> See http://shortwaveapp.com/waves.txt for instructions.
a http://www.amazon.co.uk/s/?url=search-alias%3Daps&field-keywords=%s Amazon Search.
acr http://acronyms.thefreedictionary.com/%s Acronym search.
f http://flickr.com/search/?q=%s Flickr Search
g http://www.google.com/search?q=%s Google Search
gem http://gemcutter.org/search?query=%s Search Gemcutter.
git http://www.kernel.org/pub/software/scm/git/docs/git-%s.html Git command help.
github http://github.com/search?q=%s Search Github.
gs http://www.google.com/search?q=site:%d%20%s Search the current site
require 'autotest/redgreen'
module Autotest::Growl
def self.notify(title, message, image, priority = 1, sticky = '')
`growlnotify --image #{image} -p #{priority} -m #{message.inspect} #{title} #{sticky}`
end
Autotest.add_hook :ran_command do |at|
results = [at.results].flatten.join("\n")
if output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?/)
require 'benchmark'
Dir.mkdir('results') unless File.exists?('results')
$stdout = File.new("results/#{Process.pid}.txt", 'w')
puts "Start: #{Time.now.strftime('%H:%M:%S')}"
array = (1..1000000).map { rand }; nil
Benchmark.bmbm do |x|
require 'rubygems'
require 'httparty'
class GoogleClosure
include HTTParty
base_uri 'closure-compiler.appspot.com'
def self.compile(path)
contents = File.read(path)
@benpickles
benpickles / db
Created December 22, 2009 18:55
Framework-aware console/server/database scripts.
#!/usr/bin/env ruby
require 'pathname'
require 'yaml'
conf = Pathname.new(Dir.pwd).join('config', 'database.yml')
if conf.exist?
env = ARGV.first || ENV['RAILS_ENV'] || 'development'
yaml = YAML.load(conf.read)
@benpickles
benpickles / active_model_style_errors_to_json.rb
Created March 31, 2010 16:18
ActiveModel-style (Rails 3) `errors.to_json` for your Rails 2 app
module ActiveRecord
class Errors
def to_json
inject({}) { |hash, error|
attribute, message = error
hash[attribute] ||= []
hash[attribute] << message
hash
}.to_json
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
<script src="http://github.com/documentcloud/underscore/raw/master/underscore-min.js"></script>
<script src="http://github.com/benpickles/js-model/raw/master/dist/js-model-0.8.1.min.js"></script>
<script>
var Post = Model('post', {}, {
validate: function() {
if (this.attr("title") != "Bar") {
this.errors.add("title", "should be Bar")