Skip to content

Instantly share code, notes, and snippets.

Avatar
🐕

Igor Escobar igorescobar

🐕
View GitHub Profile
@igorescobar
igorescobar / gist:3592564
Created Sep 2, 2012
converting erb to haml and haml to slim
View gist:3592564
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 Sep 14, 2012
Mascara Javascript para os novos telefones de São Paulo
View phonemask.js
// 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 Apr 21, 2020
My Personal PS1 customization to work with git repositories.
View .bashrc_ps1.sh
# 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 Oct 9, 2012 — forked from francesc/utf8encode.rake
Manage the UTF-8 encoding header for ruby 1.9
View utf8encode.rake
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 Oct 24, 2012
mongoid invalid date workaround
View mongoid_invalid_date.rb
# 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 Nov 13, 2012
Varnish Grace Mode
View default.vcl
# /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 Nov 22, 2012
Dump, export and import of a data subset
View gist:4132382
# 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 Nov 30, 2012
Ruby 1.9.3 + Passenger + RubyGems
View gist:4175595
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 Oct 13, 2015
Putting your public key into server's authorized keys.
View add-to-remote-authorized-keys.sh
scp -P 5022 ~/.ssh/id_rsa.pub USER@IP_SERVER:~/.ssh/authorized_keys
View callback_disabler.rb
# 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
}