Skip to content

Instantly share code, notes, and snippets.

View igorescobar's full-sized avatar
🐕

Igor Escobar igorescobar

🐕
View GitHub Profile
@igorescobar
igorescobar / gist:3592564
Created September 2, 2012 00:41
converting erb to haml and haml to slim
gem install haml hpricot ruby_parser slim haml2slim
rails generate devise:views
for i in `find app/views/devise -name '*.erb'` ; do html2haml -e $i ${i%erb}haml ; rm $i ; done
for i in `find app/views/devise -name '*.haml'` ; do haml2slim $i ${i%haml}slim ; done
for i in `find app/views/devise -name '*.haml'` ; do rm $i ; done
@igorescobar
igorescobar / phonemask.js
Created September 14, 2012 20:35
Mascara Javascript para os novos telefones de São Paulo
// using: https://github.com/igorescobar/jQuery-Mask-Plugin
// version: v0.5.0+
var SPphoneMask = function(phone, e, currentField, options){
return phone.match(/^(\(?11\)? ?9(5[0-9]|6[0-9]|7[01234569]|8[0-9]|9[0-9])[0-9]{1})/g) ? '(00) 00000-0000' : '(00) 0000-0000';
};
$(".sp_celphones").mask(SPphoneMask, {onKeyPress: function(phone, e, currentField, options){
$(currentField).mask(SPphoneMask(phone), options);
}});
@igorescobar
igorescobar / .bashrc_ps1.sh
Last active April 21, 2020 07:59
My Personal PS1 customization to work with git repositories.
# This bash script will update your PS1 configuration to inform you about:
# - current hour
# - current logged user
# - machine name
# - current path
# - status of current branch:
# - untracked files
# - uncommited changes
# - when nothing is changed on current branch
# - inform you when the current user.name and user.email is different of the global settings
@igorescobar
igorescobar / utf8encode.rake
Created October 9, 2012 02:06 — forked from francesc/utf8encode.rake
Manage the UTF-8 encoding header for ruby 1.9
desc "Manage the encoding header of Ruby files"
task :utf8_encode_headers => :environment do
files = Array.new
["*.rb", "*.rake"].each do |extension|
files.concat(Dir[ File.join(Dir.getwd.split(/\\/), "**", extension) ])
end
files.each do |file|
content = File.read(file)
next if content[0..16] == "# coding: UTF-8\n\n" ||
@igorescobar
igorescobar / mongoid_invalid_date.rb
Created October 24, 2012 18:46
mongoid invalid date workaround
# class SomeModel
# include Mongoid::Document
# include Mongoid::DateField
#
# date_field :date_field1, Date
# date_field :date_field2, DateTime
# date_field :date_field3, Time
# end
module Mongoid
@igorescobar
igorescobar / default.vcl
Created November 13, 2012 12:24
Varnish Grace Mode
# /etc/varnish/default.vcl
# Define the list of backends (web servers).
# Port 80 Backend Servers
backend yourapp_webserver1 {
.host = "000.000.000.000";
.port = "80";
.max_connections = 250;
.connect_timeout = 5s;
.first_byte_timeout = 5s;
.between_bytes_timeout = 5s;
@igorescobar
igorescobar / gist:4132382
Created November 22, 2012 17:58
Dump, export and import of a data subset
# dumping a data subset
mongodump --port 8080 --out /tmp/collection_name -d database_name -c collection_name --query '{"created_at" : {"$gte" : {"$date" : 1353578400000} }}'
# exporting a data subset
mongoexport --port 8080 --out /var/collection_name.json -d database_name -c collection_name --query '{"updated_at" : {"$gte" : {"$date" : 1353578400000} }}'
# importing a data subset
mongoimport --port 8080 -d database_name -c collection_name --upsert --file /var/deny/collection_name.json
@igorescobar
igorescobar / gist:4175595
Created November 30, 2012 12:58
Ruby 1.9.3 + Passenger + RubyGems
sudo su - && yum update -y
yum groupinstall "Development Tools"
yum install wget -y
yum install openssl-devel.i686 openssl.i686
cd /root && wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz
tar xvzf ruby-1.9.3-p194.tar.gz && cd ruby-1.9.3-p194
./configure --disable-install-doc --with-opt-dir=/usr/lib/openssl
make && make install
@igorescobar
igorescobar / add-to-remote-authorized-keys.sh
Last active October 13, 2015 17:47
Putting your public key into server's authorized keys.
scp -P 5022 ~/.ssh/id_rsa.pub USER@IP_SERVER:~/.ssh/authorized_keys
# In spec/support/callback_disabler.rb
module CallbackDisabler
def self.store_callbacks(model, filters)
model = constantize(model)
filters.each do |filter|
model.send("_#{filter}_callbacks").each do |callback|
stored_callbacks[model] << {
filter: filter, kind: callback.kind, raw_filter: callback.raw_filter
}