Skip to content

Instantly share code, notes, and snippets.

View devhero's full-sized avatar
😁

Andrea Parisi devhero

😁
  • devhero
  • Milan
View GitHub Profile
sudo sync && echo 3 | sudo tee /proc/sys/vm/drop_caches
@devhero
devhero / arel_case_insensitive.rb
Created September 7, 2015 09:51
arel where case insensitive
t = Table.arel_table
Table.where(t[:name].matches('%findme%'))
First, move the cursor to the first char of the first line in block code you want to comment, then type:
CTRL + V
then vim will go in to VISUAL BLOCK mode. Use j to move the cursor down until you reach the last line of your code block. Then type:
Shift + I
now vim go to INSERT mode and the cursor is at the first char of the firts line. Finally, type # then ESC and the code block is now commented.
To decomment, do the same things but instead of type Shift + I, you just type x to remove all # after highlight them in VISUAL BLOCK mode.
@devhero
devhero / remove_non_breaking_space.rb
Last active August 26, 2015 06:41
Remove a non-breaking space in Ruby - Unicode Character 'NO-BREAK SPACE' (U+00A0) - http://stackoverflow.com/questions/4859438/remove-a-non-breaking-space-in-ruby
# prepare string
d = "foo\u00A0\bar"
=> "foo \bar"
# ruby >= 1.9
d.gsub("\u00A0", "")
=> "foo\bar"
# ruby 1.8
d.gsub(/\302\240/,"")
@devhero
devhero / heroku_git_remote
Created August 13, 2015 07:04
heroku git remote
# remote list
git remote -v
# add heroku app remote
heroku git:remote --app app_name
git remote -v
# heroku https://git.heroku.com/app_name.git
# rename local remote
# See https://devcenter.heroku.com/articles/git#deploying-code
$ git push heroku yourbranch:master
@devhero
devhero / jsfiddle_console_log
Created August 3, 2015 13:36
jsfiddle console.log
# add as external resource the following library:
https://getfirebug.com/firebug-lite-debug.js
# then use console.log() into javascript panel
# list all databases
\list or \l
# list all tables in the current database
\dt
# switch databases:
\connect database_name
@devhero
devhero / pg_ident_failed
Created August 1, 2015 12:50
Postgres - Ident authentication failed for user
# edit
/var/lib/pgsql/data/pg_hba.conf
# change authentication methods from ident to md5