Skip to content

Instantly share code, notes, and snippets.

View knightq's full-sized avatar

Andrea Salicetti knightq

View GitHub Profile
@knightq
knightq / profile_utils.rb
Created February 28, 2014 09:50
Profile utils
# Usage:
# profile_memory do
# # your_code_to_be_profiled_here...
# end
module ProfileUtils
def get_current_memory_usage
`ps -o rss= -p #{Process.pid}`.to_i
end

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@knightq
knightq / rvm_setup.txt
Created November 30, 2011 09:07
RVM setup
# Install from scratch
bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
# Update
rvm get head
# Install openssl
rvm pkg install openssl #(older format - rvm package install openssl)
# Install iconv
rvm pkg install iconv # (older format - rvm package install iconv)
# In case of problem, try to install without autoreconf
@knightq
knightq / [Rails][test] - How to run one test only
Created June 7, 2012 09:36
Console script to launch one test method only in Rails
ruby -I test test/functional/items_controller_test.rb -n 'mio_test'
@knightq
knightq / gist:3077181
Created July 9, 2012 15:30
Repair MongoDB on Ubuntu
# see: http://stackoverflow.com/questions/4837427/mongo-ruby-connection-problem
sudo rm /var/lib/mongodb/mongod.lock
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
sudo start mongodb
sudo status mongodb
@knightq
knightq / Disable Rails console colors
Created January 9, 2013 13:52
Config to put in config/development.rb to disable console ANSI colors.
config.active_record.colorize_logging = false
@knightq
knightq / Rails log from console
Created January 17, 2013 15:05
How to enable Rails 2.3 logs from script/console.
ActiveRecord::Base.connection.instance_variable_set :@logger, Logger.new(STDOUT)
brew install memcached libmemcached
env ARCHFLAGS="-arch x86_64" gem install memcached --no-ri --no-rdoc -- --with-libmemcached-dir=/opt/local
@knightq
knightq / Benchmark
Created February 27, 2013 15:27
Benchmarking Ruby
# Got from here: http://www.skorks.com/2010/03/timing-ruby-code-it-is-easy-with-benchmark/
require "benchmark"
Benchmark.bm(7) do |x|
x.report("first:") { (1..10000).each { |i| i } }
x.report("second:") { (1..10000).each { |i| i }}
x.report("third:") { (1..10000).each { |i| i }}
end
@knightq
knightq / Postgres array_agg
Created April 24, 2013 13:39
Using array_agg in Postgres – powerful and flexible. Further explanation on http://craigkerstiens.com/2013/04/17/array-agg/?utm_source=postgresweekly&utm_medium=email
select array_to_string(array_agg(projects.name), ',')) as projects ...