Skip to content

Instantly share code, notes, and snippets.

View leods92's full-sized avatar

Leonardo Schlossmacher leods92

View GitHub Profile
@leods92
leods92 / order_direction_bug.rb
Last active August 29, 2015 13:58
Demonstrating a Rails 4.0.4 bug.
# Tested on Rails 4.0.4
# Rails 4.1.0.rc2 has fixed it.
require 'active_record'
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
ActiveRecord::Migration.create_table :library
ActiveRecord::Migration.create_table :books do |t|
t.string :name
@leods92
leods92 / group_date.rb
Last active December 26, 2015 14:18
Adds time zone aware data grouping method to ActiveRecord. If you want to group a large set of database rows by date using a timestamp as reference, the optimal way is to do it right in the database. When doing it though there are some issues with time zones that #group_date solves. For example, if a UTC timestamp is set to 2013-12-01 01:00 and …
module ActiveRecord
module Querying
delegate :group_date, :to => :scoped
end
module QueryMethods
def group_date(column_name = nil)
return self if column_name.blank?
# Rails uses a non standard time zone naming.
@leods92
leods92 / br_phone_validator.rb
Last active December 22, 2015 02:48
BrPhoneValidator. Validator para Rails (testado em 3.2) para validação de telefones brasileiros. Válido em 1º de setembro de 2013, em constante alteração já que celulares estão gradualmente adotando o 9º dígito.
class BrPhoneValidator < ActiveModel::EachValidator
# first 2 digits represent dialing code
# dialing codes in Brazil don't start with 0
#
# the following represent the phone
# must have 8 digits
# first digit must start with 2, 3, 4, 5 or 6
#
LANDLINE_REGEXP = /\A[1-9]\d[2-6]\d{7}\z/
@leods92
leods92 / gist:6405525
Last active December 22, 2015 02:48
Validação de números celulares no Brasil (válido em 1º de setembro de 2013).
# first 2 digits represent dialing code
# dialing codes in Brazil don't start with 0
#
# the following represent the phone
# must have 8 digits
# might have 9 if dialing code is 11, 12, 13, 14, 15, 16, 17, 18 or 19
# http://g1.globo.com/sao-paulo/noticia/2013/08/nono-digito-comeca-valer-para-telefones-celulares-do-interior-paulista.html
# first digit must start with 7, 8 or 9
# might start with 5 as well if dialing code is 11
#
@leods92
leods92 / dabblet.css
Created August 13, 2012 20:07
Untitled
a[target] {
display: inline;
}
a[target]::before {
content: "this is a link => ";
margin: 0 4px 0 2px;
}
@leods92
leods92 / dabblet.css
Created August 13, 2012 19:46
Untitled
a[target]::before {
content: "this is a link => ";
margin: 0 4px 0 2px;
}
@leods92
leods92 / dabblet.css
Created August 13, 2012 19:37
Untitled
a::before {
content: "this is a link => ";
margin: 0 4px 0 2px;
}
{
"name": "awesome-project",
"version": "0.1.0",
"dependencies": {
"mysecretproject": "https://dl.dropbox.com/s/randomcharshere/mysecretproject.tar.gz?dl=1"
}
}
@leods92
leods92 / git_to_dropbox.sh
Created June 30, 2012 19:04
Shell script to pack git repository in a tarball and place it in Dropbox folder
#!/bin/sh
GIT_REPO="/path/to/git/repo"
cd $GIT_REPO
git archive --format=tar --prefix=package/ master | gzip > ~/Dropbox/repo.tar.gz && open ~/Dropbox
echo "Now generate the Dropbox link and add it to package.json."
@leods92
leods92 / gist:2949276
Created June 18, 2012 16:33
Javascript Car class
var Car
, prius
;
Car = function(b, m, y) {
this.brand = b;
this.model = m;
this.year = y;
};