Skip to content

Instantly share code, notes, and snippets.

View elhoyos's full-sized avatar

Juan Hoyos elhoyos

View GitHub Profile
@elhoyos
elhoyos / gist:6000770
Created July 15, 2013 15:15
Zero-width spaces
http://en.wikipedia.org/wiki/Zero-width_space
http://www.utf8-chartable.de/unicode-utf8-table.pl?start=8192
\A[A-J][^.[:space:]\u{200B 200C 200D FEFF}]
http://stackoverflow.com/a/11305926/638425
@elhoyos
elhoyos / gist:6214093
Created August 12, 2013 19:13
How to check a column is empty or NULL
SELECT * FROM table
WHERE column > ''
@elhoyos
elhoyos / README.md
Last active December 25, 2015 17:39
Do this instead of... Simple Git suggestions to make our life easier

When merging to a non-feature branch you'd normally use git merge <branch>. You can do better for the sake of easier reverts and help the review process:

git merge --no-ff <branch> 

The naive way to update from upstream is git pull but is better to try:

git up
@elhoyos
elhoyos / gist:7451129
Created November 13, 2013 15:40
Initialize default values in Rails
# From: http://stackoverflow.com/a/5127684/638425
# WARNING: See the caveats.
class Person
has_one :address
after_initialize :init
def init
self.number ||= 0.0 #will set the default value only if it's nil
self.address ||= build_address #let's you set a default association
@elhoyos
elhoyos / gist:7875911
Last active December 30, 2015 19:39
Nokogiri adds \n between tags when using to_html and to_xml

Nokogiri adds \n between tags when using to_html and to_xml

Credits: These were identified and collected by @amirisnino

to_html

Example 1:

require 'nokogiri'
string = 'a<div>b<br><br></div>'
html_doc =  Nokogiri::HTML::DocumentFragment.parse(string)
require 'benchmark'
# Constant vs String comparison benchmark
class AType; end
types = []
(1..10000).each { types.push(AType) }
time = Benchmark.realtime do
@elhoyos
elhoyos / gist:9464937
Created March 10, 2014 13:29
Fixing an EMFILE error
@elhoyos
elhoyos / gist:9902724
Created March 31, 2014 21:24
*** glibc detected *** [....]: corrupted double-linked list: [...] ***
OS: Centos 6.4 (Final)
ruby: 1.9.3p327
ImageMagick: ImageMagick 6.5.4-7 2014-02-10 Q16 OpenMP
RMagick: 2.13.2
@elhoyos
elhoyos / gist:6cdedd5659de7110e9ca
Created June 19, 2014 22:02
Add your public ssh key as an authorized key
$ cat ~/.ssh/id_rsa.pub | ssh root@server.com 'cat >> .ssh/authorized_keys'
@elhoyos
elhoyos / binary
Last active May 25, 2016 21:34
mongo: Copy a collection
$ mongodump -d some_database -c some_collection
$ mongorestore -d some_other_db -c some_or_other_collection dump/some_collection.bson