Skip to content

Instantly share code, notes, and snippets.

View marcocarvalho's full-sized avatar

Marco Carvalho marcocarvalho

  • mcorp.io
  • Curitiba - PR - Brasil
View GitHub Profile
@marcocarvalho
marcocarvalho / combo_helper.rb
Created June 25, 2011 17:38
Rails 3 FormBuilder Select Helper that deals with association
#
# ~/app/helpers/combo_helper.rb
#
# Association => { { id: 1, association: "Coolest" } , { id: 2, association: "Hardest" } }
#
# Model Class << ActiveRecord::Base
# has_many :associations
# end
#
# Use:
@marcocarvalho
marcocarvalho / hash.rb
Created September 3, 2012 13:06
Hash with Initial value
# Ao invés de fazer:
# dentro de uma iteração
h = {}
h[:somekey] = {} if h[:somekey].nil?
h[:somekey][:otherkey] = [] if h[:somekey][:otherkey].nil?
h[:somekey][:otherkey] << item_da_teracao
# Teremos um hash: { somekey: { :otherkey => [1, 2, 3, 4] } }
@marcocarvalho
marcocarvalho / ruby-gzip-alike.rb
Created July 2, 2013 19:50
Create gzip readable files using ruby zlib
fn = "filename"
compressed_file_name = "#{fn}.gz"
Zlib::GzipWriter.open(compressed_file_name) do |gz|
gz.mtime = File.mtime(fn)
gz.orig_name = fn
gz.write IO.binread(fn)
end
@marcocarvalho
marcocarvalho / excel_spreedsheet_column_notation_calculator
Last active December 21, 2015 21:08
Excel / SpreedSheet column notation calculator in ruby
#!/usr/bin/env ruby
module Spreedsheet
module ColumnNotation
def seed
@seed ||= ('A'..'Z').to_a
end
def position_to_column_notation(num, minus = 0)
m = num.divmod(seed.size)
@marcocarvalho
marcocarvalho / seeds.rb
Last active December 23, 2015 02:49 — forked from dcrec1/seeds.rb
states = <<STATES
AC,Acre
AL,Alagoas
AP,Amapá
AM,Amazonas
BA,Bahia
CE,Ceará
ES,Espírito Santo
GO,Goiás
MA,Maranhão
dpkg -l linux-* | grep -v libc | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get -y purge
#!/bin/bash
sudo aptitude update
sudo aptitude -y install build-essential openssl libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev autoconf libc6-dev libncurses5-dev automake libtool bison subversion libffi-dev

Capybara

save_and_open_page

Matchers

have_button(locator)
@marcocarvalho
marcocarvalho / yardoc_cheatsheet.md
Last active August 29, 2015 14:26 — forked from chetan/yardoc_cheatsheet.md
YARD cheatsheet

YARD CHEATSHEET http://yardoc.org

cribbed from http://pastebin.com/xgzeAmBn

Templates to remind you of the options and formatting for the different types of objects you might want to document using YARD.

Modules

Namespace for classes and modules that handle serving documentation over HTTP

upstream unicorn_server {
server unix:/tmp/unicorn.sock fail_timeout=0;
}
server {
listen 80;
root /usr/src/app/public;
try_files $uri @unicorn_server;