Skip to content

Instantly share code, notes, and snippets.

@pcreux
pcreux / martine-fetcher.rb
Created October 5, 2011 10:34
Fetch martines!
require 'rubygems'
require 'mechanize'
martine_ids = []
agent = Mechanize.new
(1..20).each do |page_number|
page = agent.get("http://www.nintendo-town.fr/martine/index.php?p=#{page_number}&f=3&s=")
page.links.each do |link|
@pcreux
pcreux / .zshrc
Created October 24, 2011 09:48
Alias: git compare
alias git-compare='(git diff master...HEAD --stat --color && git diff master...HEAD --color) | less -R'
@pcreux
pcreux / pomodoro
Created October 28, 2011 08:51
Pomodoro timer for ubuntu unity
#!/usr/bin/env ruby
#
# Pomodoro script.
#
# Displays a notification after 25 minutes.
#
# Don't forget to 'sudo apt-get install libnotify-bin'
#
system "notify-send -i face-cool 'Go go go!'"
@pcreux
pcreux / batch_review.rb
Created November 23, 2011 16:39
Batch gitmine review a bunch of tickets.
#!/user/env ruby
#
# Batch gitmine review a bunch of tickets.
#
# Usage: ruby batch_review.rb 7585 7603 7623 7640 7663 7665
#
ARGV.each do |issue_id|
system("gitmine checkout #{issue_id} && git pull && git diff master...HEAD")
puts "Merge into master?"
@pcreux
pcreux / delegate_matcher.rb
Created December 1, 2011 11:47 — forked from txus/delegate_matcher.rb
RSpec matcher for delegations
# RSpec matcher to spec delegations.
#
# Usage:
#
# describe Post do
# it { should delegate(:title).to(:name) } # post.title => post.name
# it { should delegate(:month).to(:created_at) } # post.month => post.created_at
# it { should delegate(:author_name).to(:author, :name) } # post.author_name => post.author.name
# end
@pcreux
pcreux / test.rb
Created December 12, 2011 14:36
Create a commit on github via API v3
require 'rubygems'
require 'httparty'
class Github
include HTTParty
base_uri "https://api.github.com/repos/pcreux/test-pimp-my-changelog"
basic_auth "pcreux", ENV['GITHUB_PASSWORD']
format :json
debug_output
@pcreux
pcreux / dp.rb
Created December 13, 2011 12:11
Decorators VS Presenters
class BankAccount < Model
end
# Decorate a model
class BankAccountDecorator
def human_name
end
end
# Present several models. Have built-in logic.
@pcreux
pcreux / helpers.rb
Created January 9, 2012 07:26
rspec describe with subject
# Create a describe block and set its subject to 'instance_eval(@subject_name)'
# Example:
#
# Instead of:
#
# describe :transaction do
# subject { transaction }
# its(:state) { should == 'completed' }
# end
#
@pcreux
pcreux / foreign_key_helpers.rb
Created January 13, 2012 10:25
Foreign Key Helper for ActiveRecord migrations (tested on MySQL)
module ForeignKeyHelpers
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
# Add a foreign key constraint binding :table :column to the 'id' column of the target_table
#
# By default, a column called 'user_id' will be binded to the column 'id' of the
# table 'users' via a foreign key called 'fk_:table_:column_:target_table'.
@pcreux
pcreux / model_spec.rb
Created January 16, 2012 10:00
Sample spec
require 'spec_helper'
describe User do
# Use rspec-set to create a test user once
set(:user) { Factory(:user) }
describe "validations" do
it { should validate_presence_of :email }
it { should validate_confirmation_of :password }
end