I hereby claim:
- I am alexisbernard on github.
- I am alexis_bernard (https://keybase.io/alexis_bernard) on keybase.
- I have a public key whose fingerprint is FCA3 D196 1FB9 7CF8 7EAD D95D 2712 9EF2 E8A7 447B
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
# Convenient way to fetch URLs. It follows redirections and handles SSL. Usage: | |
# Net::HTTP.fetch_url('http://google.com') | |
# Net::HTTP.fetch_url('https://www.google.fr/?q=ruby') | |
module Net | |
class HTTP | |
def self.fetch_url(url, limit = 10) | |
raise ArgumentError, 'HTTP redirect too deep' if limit == 0 | |
url = URI.parse(url) | |
options = {use_ssl: url.scheme.downcase == 'https'} | |
request = Net::HTTP::Get.new(url.path.to_s + '?' + url.query.to_s) |
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAznBfbfnCJMibMMPSI7Fxeo02Y9fgy7yrMVlON2AKhTB3QMhjUORqONRCQG6g1qHJX2Osg/NQ6kxZEU7pHC8aTCXpPnKMrSWz/73B3vSsfV2dZIp1q5pz35MGqCkXKhfM7xO8NHGbzzVOs9mNb0txWU1fPI9parPqCvosjFKN5uJDpMUKV3yVwqztsSgRp9hwMtErg5SkBeRbFYRl2Aa1pEmRwjwdQyS23B4uwus9cFE2xkR86FOkJu4/5Rr1WKmqOLFyObjk1MSwYqfmHtCgwO0GWB3OTYtQbBD/4UC159efKDKvivVqCnItzg2huHsSRr4JugnQ7AIpKhbnrIUx9w== alexis |
# InfiniteStringStub.new.foo.bar.baz # => 'baz' | |
class InfiniteStringStub < String | |
def method_missing(name) | |
InfiniteStringStub.new(name.to_s) | |
end | |
end |
#!/bin/sh | |
# File: .git/hooks/prepare-commit-msg | |
# Append the Pivotal's story tag at the end of the commit message. | |
# Your branch must be named like this: my_branch_12345. | |
story=$(git symbolic-ref HEAD|sed -rn 's/^.*_([[:digit:]]+)/\1/p') # -E instead of -r for Mac OS X | |
test $story && echo "[Story#$story]" >> $1 | |
exit 0 |
$LOAD_PATH.unshift '/home/alexis/veritas/lib' | |
require 'veritas' | |
include Veritas | |
header = Relation::Header.new([[:name, String], [:is_admin, Integer], [:is_author, Integer]]) | |
body = [['Foo', 1, 1], ['Bar', 1, 0], ['Baz', 0, 1]].each | |
users = Relation.new(header, body) | |
admins = Relation.new(header, body).restrict { |r| r[:is_admin].eq(1) } |
# Called dynamically named scopes on a model | |
module Fluent | |
module Scopes | |
def self.included(klass) | |
klass.extend(ClassMethods) | |
# The code below fixes the following statement: | |
# @project = Project.find(123) | |
# @project.developers.apply_scopes(filters).find | |
# Without the code below the condition where developers.project_id = 123 is erased | |
# by apply_scopes, because filters are built from the class Developer instead of |
# Fluent Factory overrides the new class method to provide an intuitive factory. | |
# Instead of using | |
# MyFactory.new_instance(args) | |
# Which may return an instance of MyClass, you now use | |
# MyClass.new(args) | |
# The second way is more intuitive and the big advantage is to use it rails and | |
# inheritance. | |
# | |
# Read the full example below to understand how to use it. | |
# class Animal |
# Generates a random String | |
# 'abc'.rand(10) # => 'aacbacccbc' | |
class String | |
def rand(length) | |
(1..length).inject('') {|str, i| str << self[Kernel::rand(self.length)]} | |
end | |
end |
# This enables the '/' resource: | |
# map.resources :knickers, :as => '' | |
# | |
# GET /blabla | |
# => KnickersController#show params = {:controller = 'knickers', :action => 'show, :id => 'blabla'} | |
module ActionController | |
module Resources | |
class Resource #:nodoc: | |
def path | |
@path ||= path_segment.blank? ? path_prefix.to_s : "#{path_prefix}/#{path_segment}" |