Skip to content

Instantly share code, notes, and snippets.

View tonycoco's full-sized avatar

Tony Coconate tonycoco

View GitHub Profile
@tonycoco
tonycoco / heroku-pg-backup.sh
Last active August 29, 2015 13:56
Heroku PG Backup
curl -o latest.dump `heroku pgbackups:url`
rake db:drop db:create db:migrate
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U root -d DATABASE_development latest.dump
rm latest.dump
@tonycoco
tonycoco / select2.rb
Created February 19, 2014 17:28
Select2 Capybara Support File
# Useage: select2("value to select", from: "label text")
module Capybara
module Select2
def select2(value, options={})
select_name = options[:from]
select2_container = first("label", text: select_name).find(:xpath, "..").find(".select2-container")
select2_container.find(".select2-choice").click
find(:xpath, "//body").find(".select2-drop li", text: value).click
end
@tonycoco
tonycoco / uploader_input.rb
Last active August 29, 2015 14:08
Carrierwave Uploader (with Cloudinary support) Input for ActiveAdmin's Formtastic Inputs
class UploaderInput < Formtastic::Inputs::FileInput
MAX_WIDTH_PIXELS = 300
MAX_HEIGHT_PIXELS = 200
def to_html
input_wrapping do
html_array = []
html_array << label_html
html_array << cache_html if method_changed?
html_array << file_html
@tonycoco
tonycoco / ember-cli-update.sh
Created January 15, 2015 16:30
Ember CLI Project Update Bash Function
function ember-cli-update {
if [ -z "$1" ]; then
echo "$(tput setaf 1)No Ember CLI version has been specified. Example: ember-cli-update 0.1.7$(tput sgr 0)"
return 1
fi
echo "$(tput setaf 2)Uninstalling global Ember CLI...$(tput sgr 0)"
npm uninstall -g ember-cli
echo "$(tput setaf 2)Cleaning NPM and Bower cache...$(tput sgr 0)"
# Get this working in an initializer...
%w(zipcode, city, designated_market_area, core_based_statistical_area).each do |t|
Zips::<t's classified name here>.set_schema("")
Zips::<t's classified name here>.set_table_name("zips_#{t.pluralize}")
end
@tonycoco
tonycoco / My IRBRC
Created April 1, 2011 15:21
Just a few good things to do for your Rails 3 applications in IRBRC
%w[rubygems wirble pp ap].each do |gem_name|
begin
require gem_name
rescue LoadError => err
warn "Please do: gem install #{gem_name.sub(/\/.*/,'')}"
end
end
Wirble.init
Wirble.colorize
@tonycoco
tonycoco / gist:1528711
Created December 28, 2011 17:08
TextMate Patterns
File:
!(/\.(?!htaccess)[^/]*|\.(tmproj|o|pyc)|/Icon\r|/svn-commit(\.[2-9])?\.tmp)$
Folder:
!.*/(\.[^/]*|doc|log|solr|public/uploads|public/system|tmp|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$
@tonycoco
tonycoco / pow_debugger
Created April 10, 2012 03:54
POW! Debugger
# Debugging with POW!
#
# Setup POW!'s ~/.powconfig with the following:
# export POW_WORKERS=1
# export POW_TIMEOUT=3600
#
# Run `bundle exec rdebug -c` in the Terminal to start the debugger
if (Rails.env.development? || Rails.env.test?) && !(defined?($rails_rake_task) && $rails_rake_task)
puts "=> Debugger enabled"
@tonycoco
tonycoco / rubyhashsyntax.rb
Created May 11, 2012 17:17
Confusing Ruby Hash Syntax
# New
range :percentile, from: percentile[0], to: 1
# Old
range :percentile, :from => percentile[0], :to => 1
@tonycoco
tonycoco / config.ru
Created July 11, 2012 16:40
Rack It Up... Using POW! with PHP (Or, rather using PHP with Rack)
# config.ru for Pow + Wordpress, based on http://stuff-things.net/2011/05/16/legacy-development-with-pow/
# added hackery to work around wordpress issues - Patrick Anderson (patrick@trinity-ai.com)
# clearly this could be cleaner, but it does work
require 'rack'
require 'rack-legacy'
require 'rack-rewrite'
# patch Php from rack-legacy to substitute the original request so
# WP's redirect_canonical doesn't do an infinite redirect of /