Skip to content

Instantly share code, notes, and snippets.

View lucascaton's full-sized avatar

Lucas Caton lucascaton

View GitHub Profile
@lucascaton
lucascaton / Gemfile
Created December 13, 2014 05:48
Car Sales checker (Ruby script)
source 'https://rubygems.org'
gem 'mechanize'
gem 'pry'
@lucascaton
lucascaton / oferta_irresistivel.md
Last active August 1, 2016 08:53
Crie sua Oferta Irresistível
%w(1 2).sort_by { |i| nil }
# => ["1", "2"]
# ...
%w(1 2 3 4 5 6).sort_by { |i| nil }
# => ["1", "2", "3", "4", "5", "6"]
### So far, so good...
### But look what happens when you have 7 or more elements:
@lucascaton
lucascaton / array.swift
Last active February 22, 2016 09:15
By using functions like the following, it prevents app from crashing if you pass the wrong index (tip from @CassiusPacheco)
public extension Array {
    public subscript(safe index: Int) -> Element? {
        return self.indices ~= index ? self[index] : nil
    }
}
// ...
let optionalResult = array[safe: 1] // returns nil instead of crashing
(1..50).to_a.first # => 1
(1..50).to_a.second # => 2
(1..50).to_a.third # => 3
(1..50).to_a.fourth # => 4
(1..50).to_a.fifth # => 5
(1..50).to_a.forty_two # => 42
#!/usr/bin/env ruby
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
@lucascaton
lucascaton / capybara_cheat_sheet.rb
Last active December 30, 2015 02:09 — forked from zhengjia/capybara cheat sheet
Capybara cheat sheet
# Navigating
visit '/projects'
visit post_comments_path(post)
# Clicking links and buttons
click_link 'id-of-link'
click_link 'Link Text'
click_button 'Save'
click 'Link Text' # Click either a link or a button
click 'Button Value'
@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 ruby
require 'fileutils'
def make_tests_specs(current_path)
current_path[:test_unit_directory].each do |file|
unless file == '.' or file == '..'
full_file = File.join(current_path[:test_unit_directory].path, file)
if File.directory?(full_file)
#!/bin/bash
# Usage: after_merge branch_name
branch="$1"
git checkout master
git pull --rebase
git remote prune origin
git branch -d $branch