Skip to content

Instantly share code, notes, and snippets.

@lucasfais
lucasfais / gist:1207002
Created September 9, 2011 18:46
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@jwo
jwo / registrations_controller.rb
Created September 30, 2011 23:11
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@dolzenko
dolzenko / factory_girl_debugging.rb
Created January 25, 2012 10:42
Commands to debug Factory Girl from console
require 'factory_girl_rails'
require 'rspec'
require 'rspec-rails'
require 'rspec/mocks/standalone' # => if factories need stubs (for remote services for example)
include FactoryGirl::Syntax::Methods # make FG methods available at top level, so you can do `> create :user`
def reload_factories!
FactoryGirl.instance_variable_set(:@factories, nil) # => clear loaded factories/sequences
# FactoryGirl.instance_variable_set(:@sequences, nil)
@ProfAvery
ProfAvery / sum.rb
Created February 9, 2012 05:39
15 ways to sum an array in Ruby
#!/usr/bin/env ruby
require 'test/unit'
class TestSums < Test::Unit::TestCase
def setup
@a = [2, 5, 18, 27]
@sum = 0
end
@l4u
l4u / optimize.rb
Created March 31, 2012 11:14
Optimizing PNGs
Dir.glob("**/*.png").each do |file|
['pngnq -e .png -f', 'pngquant -f -speed 1 -ext .png', 'pngcrush'].each do |command|
puts "#{command} #{file}"
`#{command} #{file}`
end
end
@MicahElliott
MicahElliott / rbenv-howto.md
Created April 17, 2012 18:11
Setting up and installing rbenv, ruby-build, rubies, rbenv-gemset, and bundler

Setting up and installing rbenv, ruby-build, rubies, rbenv-gemset, and bundler

This guide enables you to install (ruby-build) and use (rbenv) multiple versions of ruby, isolate project gems (gemsets and/or bundler), and automatically use appropriate combinations of rubies and gems.

TL;DR Demo

# Ensure system is in ship-shape.

aptitude install git zsh libssl-dev zlib1g-dev libreadline-dev libyaml-dev

@rtwomey
rtwomey / Heroku DB Migration.mdown
Created July 23, 2012 18:47
How to migrate a DB on heroku to another plan

Recently, I had a staging database on Heroku that was running on the Ronin database (which was originally the lowest-sized DB you could get at Heroku). Since they added two new options, Crane and Kappa, we wanted to take advantage of the cost savings. Here's how you can migrate your Ronin DB to Crane (or any other plan).

The old database was named BROWN while the new one is CRIMSON. You can determine this by running:

heroku pg:info --app myapp-staging
  1. Add Crane database

     heroku addons:add heroku-postgresql:crane --app myapp-staging
    

heroku pg:wait --app myapp-staging

Spree::Order.class_eval do
silence_warnings do
state_machines.clear
#override state_machine to add choose_reward step
state_machine :initial => 'cart', :use_transactions => false do
event :next do
transition :from => 'cart', :to => 'address'
transition :from => 'address', :to => 'delivery'
transition :from => 'delivery', :to => 'payment', :if => :payment_required?
transition :from => 'delivery', :to => 'complete'
@olistik
olistik / gist:3894072
Created October 15, 2012 18:09
Ubuntu 12.04 Terminator config: solarized theme + iTerm2-like key bindings
# place this file in ~/.config/terminator/config
[global_config]
title_transmit_bg_color = "#d30102"
focus = system
[keybindings]
reset_clear = <Ctrl>R
new_tab = <Ctrl>T
split_horiz = <Ctrl><Shift>E
split_vert = <Ctrl>E
close_term = <Ctrl><Shift>W
@zhiyao
zhiyao / Heroku db task
Created October 30, 2012 16:10
Heroku database backup, transfer between production and staging server, alot faster that the heroku db:pull and db:push. This will only work if your local app is setup with postgres database
#!/usr/bin/env ruby
#Place this in your root directory of your rails app
#Ensure that you have install thor gem
#To list the command, type 'thor -T'
module Heroku
class Db < Thor
desc "production_to_local", "clone a remote heroku database to the local environment"
method_option :remote_production, :type => :string, :default => 'production'