Skip to content

Instantly share code, notes, and snippets.

View lucascaton's full-sized avatar

Lucas Caton lucascaton

View GitHub Profile
@lucascaton
lucascaton / boot.rb
Last active December 29, 2015 14:59 — forked from lloeki/boot.rb
Monkeypatching Rails 2.3.x to boot Thin by default.
# (...)
Rails.boot!
# The code below allow to use Thin as the webserver
if $0 == 'script/server'
# commands/server.rb (#45) is not cooperative, so we patch Rack itself
require 'rack'
module Rack::Handler
class << self
#!/usr/bin/env bash
INSTALL_DIR="${INSTALL_DIR:-/opt/local}"
VERSION=$2
YAML_VERSION="0.1.4"
APP_NAME="ruby"
URL="http://ftp.ruby-lang.org/pub/ruby/ruby-$VERSION.tar.bz2"
YAML_URL="http://pyyaml.org/download/libyaml/yaml-$YAML_VERSION.tar.gz"
PREFIX="$INSTALL_DIR/$APP_NAME/$VERSION"
YAML_PREFIX="$INSTALL_DIR/yaml"
require 'RMagick'
require 'capybara'
require 'launchy'
module Capybara::Recording
def start_recording
system "rm -f tmp/*"
end
def save_recording
@lucascaton
lucascaton / pre-commit
Created December 9, 2015 00:04 — forked from jonasschmidt/pre-commit
git pre-commit hook checking for RSpec :focus tags that were unintentionally left in the specs
#!/usr/bin/env ruby
if `git diff --cached spec` =~ /,\s?(:focus|focus:\s?true|:focus\s?=>\s?true)/
puts "\e[31mPlease focus and remove your :focus tags before committing :)"
exit 1
end
class Application < ActiveRecord::Base
attr_accessible :checksum, :name, :size, :configuration_attributes
has_one :configuration, :dependent => :destroy
accepts_nested_attributes_for :configuration, :allow_destroy => :true
after_initialize :create_new_configuration
private
<%= form_for @application, :html => { :class => 'form-horizontal' } do |f| %>
<div class="control-group">
<%= f.label :name, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :name, :class => 'text_field' %>
</div>
</div>
<div class="control-group">
<%= f.label :checksum, :class => 'control-label' %>
<div class="controls">
@lucascaton
lucascaton / gist:2967185
Created June 21, 2012 17:31
Exemplo "feio" de ElasticSearch
class Person < ActiveRecord::Base
include Tire::Model::Search
include Tire::Model::Callbacks
has_many :addresses
accepts_nested_attributes_for :addresses, :allow_destroy => true
def to_indexed_json
{
:addresses => adresses.map{|p| p.name}.compact.reject(&:blank?).uniq,
@lucascaton
lucascaton / integration_test.rb
Created June 11, 2012 19:06 — forked from tomas-stefano/integration_test.rb
Fast Specs! Unit, model and integration tests
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'machinist/active_record'
require 'machinist/caching/active_record'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
spec_support = Rails.root.join("spec/support/**/*.rb")
@lucascaton
lucascaton / itunes_match_tips.txt
Created June 10, 2012 22:10 — forked from rmhall/itunes_match_tips.txt
iTunes Match tips
My iTunes Match Track upgrading and process info:
If you have less than 25,000 tracks:
1. First let iTunes Match do its things and find all possible matches in your library and finish uploading any non-matching tracks.
2. Once its done, make a new Smart Playlist (I made a folder for all my Smart iTunes Match Related Playlists)
Name this one: iCloud-Upgradeable
Criteria:
MATCH ALL:
Bit Rate is less than 256kbps
@lucascaton
lucascaton / gist:2420977
Created April 19, 2012 13:27 — forked from fnando/gist:2420869
My JavaScript Guidelines