Skip to content

Instantly share code, notes, and snippets.

Avatar
🐕

Igor Escobar igorescobar

🐕
View GitHub Profile
@igorescobar
igorescobar / hal_builder_spec.js
Created May 20, 2014
Testing sequelizejs success callback with mocked data
View hal_builder_spec.js
/*globals describe, it, context*/
/*jslint node: true, indent: 2*/
'use strict';
var HalBuilder,
chai = require('chai'),
should = chai.should(),
assert = chai.assert,
expect = chai.expect,
@igorescobar
igorescobar / mustache-global-helper.js
Created Aug 18, 2015
Registering global mustache helpers
View mustache-global-helper.js
function i18nLambda (text, render) {
text = dict[text] || text
return render(text)
}
var Context = mustache.Context
Context.prototype._lookup = Context.prototype.lookup
Context.prototype.lookup = function i18nLookup (name) {
return (name === 'i18n' ? i18nLambda : this._lookup(name)
}
@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 / 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
}