Skip to content

Instantly share code, notes, and snippets.


Tiago Scolari tscolari

View GitHub Profile
tscolari / shared_examples_default_crud_routing.rb
Created May 6, 2011 00:00
This is a set of tests for default CRUD routing in rails. Also works with namespaces.
View shared_examples_default_crud_routing.rb
shared_examples_for "default crud routing" do
let(:random_id_for_routing) {rand(2000)}
let(:controller_name) {described_class.to_s.underscore.gsub(/_controller/, '')}
it "should route to index action" do
{:get => "/#{controller_name}"}.should route_to(
:controller => controller_name,
:action => 'index'
tscolari / Gemfile
Created August 15, 2012 21:20
Octopress S3 Deploy Method
View Gemfile
# ....
gem 'aws-s3'
# ....
tscolari / s3_upload_files.rb
Created August 16, 2012 19:05
S3 multiple file uploader
View s3_upload_files.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'aws/s3'
# If you use a directory as parameter, every file inside it will be uploaded.
# ex: ./s3_upload_files /system/backups/
# If you use a text file as parameter, it should have one file name per line, all files listed will be uploaded.
# ex: ./s3_upload_files changeset
tscolari / factories_spec.rb
Last active October 9, 2015 06:18
Spec for all factories
View factories_spec.rb
require 'spec_helper'
describe FactoryGirl do
FactoryGirl.factories.each do |factory|
context "with factory for :#{}" do
subject {}
it "is valid" do
subject.valid?.should be, subject.errors.full_messages.join(',')
tscolari / thinking_sphinx.rake
Last active May 25, 2017 10:05
Thinking-Sphinx Run in Foreground Task
View thinking_sphinx.rake
namespace :ts do
desc "Run Thinking Sphinx in the foreground (for something like foreman)"
task :run_in_foreground => ['ts:stop', 'ts:index'] do
config = ThinkingSphinx::Configuration.instance
controller = config.controller
unless pid = fork
exec "#{controller.bin_path}#{controller.searchd_binary_name} --pidfile --config #{config.configuration_file} --nodetach"
tscolari / vim.rb
Created September 26, 2012 16:45 — forked from bmatheny/vim.rb
Vim Formula with Ruby & Python support for OS X
View vim.rb
require 'formula'
class Vim < Formula
homepage ''
version '7.3.666'
url '', :revision => '1e22adc6176e'
head ''
def ruby_bin
tscolari / kd_tree.rb
Created December 14, 2012 20:15
Simple KDTree implementation to find the nearest point to another
View kd_tree.rb
# Simple KDTree class with sorting for finding nearest neighbor
class KDTree
class Node <, :left, :right)
# Public: Returns the distance of the object to the
# point
def distance_to(point)
throw "Points have different dimensions" if point.size != value.size
square_sum = 0
tscolari / rcodetools.vim
Last active December 19, 2015 19:39
rcodetools.vim to use with vundles source:
View rcodetools.vim
" Copyright (C) 2006 Mauricio Fernandez <>
" rcodetools support plugin
if exists("loaded_rcodetools")
let loaded_rcodetools = 1
let s:save_cpo = &cpo
tscolari /
Last active December 20, 2015 05:38
Commit with story id
  • add prepare-commit-msg it to ./.git/hooks/
  • Make it executable (chmod +x filename)

It should prepend [#STORY_ID] into your commit message when the editor pops up. Your branch must be in this format to work: branch-description-blabla-STORY_ID

it skips the prepaend if:

  • The branch doesn't end in a story id (integer)
  • The original commit message starts with "Merge"
tscolari /
Created July 26, 2013 09:07
Work in progress
  • Avoids files with debugger/binding.pry to be commited
  • Avoids files with spaces in the end of the line to be commited


  • Copy the file to .git/hooks/pre-commit
  • Make it executable chmod + x .git/hooks/pre-commit
  • Have fun