Skip to content

Instantly share code, notes, and snippets.

Tiago Scolari tscolari

View GitHub Profile
@tscolari
tscolari / shared_examples_default_crud_routing.rb
Created May 6, 2011
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
tscolari / Gemfile
Created Aug 15, 2012
Octopress S3 Deploy Method
View Gemfile
# ....
gem 'aws-s3'
# ....
@tscolari
tscolari / s3_upload_files.rb
Created Aug 16, 2012
S3 multiple file uploader
View s3_upload_files.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'aws/s3'
## USAGE
#
# 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
tscolari / factories_spec.rb
Last active Oct 9, 2015
Spec for all factories
View factories_spec.rb
require 'spec_helper'
describe FactoryGirl do
FactoryGirl.factories.each do |factory|
context "with factory for :#{factory.name}" do
subject {FactoryGirl.build(factory.name)}
it "is valid" do
subject.valid?.should be, subject.errors.full_messages.join(',')
end
@tscolari
tscolari / thinking_sphinx.rake
Last active May 25, 2017
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"
end
@tscolari
tscolari / vim.rb
Created Sep 26, 2012 — forked from bmatheny/vim.rb
Vim Formula with Ruby & Python support for OS X
View vim.rb
require 'formula'
class Vim < Formula
homepage 'http://www.vim.org/'
version '7.3.666'
url 'https://vim.googlecode.com/hg/', :revision => '1e22adc6176e'
head 'https://vim.googlecode.com/hg/'
def ruby_bin
@tscolari
tscolari / kd_tree.rb
Created Dec 14, 2012
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 < Struct.new(:value, :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
tscolari / rcodetools.vim
Last active Dec 19, 2015
rcodetools.vim to use with vundles source: https://github.com/tnoda/rcodetools
View rcodetools.vim
" Copyright (C) 2006 Mauricio Fernandez <mfp@acm.org>
" rcodetools support plugin
"
if exists("loaded_rcodetools")
finish
endif
let loaded_rcodetools = 1
let s:save_cpo = &cpo
@tscolari
tscolari / aaa-prepare-commit.md
Last active Dec 20, 2015
Commit with story id
View aaa-prepare-commit.md
  • 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
tscolari / aa.md
Created Jul 26, 2013
Work in progress
View aa.md
  • Avoids files with debugger/binding.pry to be commited
  • Avoids files with spaces in the end of the line to be commited

Instalation

  • Copy the file to .git/hooks/pre-commit
  • Make it executable chmod + x .git/hooks/pre-commit
  • Have fun
You can’t perform that action at this time.