Skip to content

Instantly share code, notes, and snippets.

View nesquena's full-sized avatar

Nathan Esquenazi nesquena

View GitHub Profile
@nesquena
nesquena / a.md
Created November 27, 2012 23:53
RABL Testing Reference

Common Misunderstandings

Serialization should be testable

Agreed and with RABL serialization is testable both in and outside of a web request context. Check out the other gists in this file for examples using Rabl.render to do standalone unit testing.

RABL can't be used for generating push notifications or in background jobs

Not at all true, I use RABL for these purposes in all of my applications. Simply use Rabl.render to render templates in any context.

@nhance
nhance / method_logger.rb
Created September 6, 2012 12:58
Rails compatible method logging. Use this to log all calls to instance methods of a class to the log.
Model.new.foo
@nesquena
nesquena / minitest_steps.md
Created November 30, 2011 21:03
Setup Minitest in a Gem

Minitest Steps

Add to gemspec:

# my_gem.gemspec

Gem::Specification.new do |s|
  # ...
 
@nesquena
nesquena / basic.sql
Created September 7, 2011 01:56
PostgreSQL Common Utility Queries
/* How to calculate postgreSQL database size in disk ? */
SELECT pg_size_pretty(pg_database_size('thedbname'));
/* Calculate size of a table including or excluding the index */
SELECT pg_size_pretty(pg_total_relation_size('big_table'));
SELECT pg_size_pretty(pg_relation_size('big_table')); /* without index */
/* See indexes on a table with `\d tablename` */
@nesquena
nesquena / request.rb
Created May 10, 2011 00:44
Rails Request Logging
Rails.logger.info "REQUEST INSPECTOR"
Rails.logger.info " [REQUEST_URI] #{request.headers['REQUEST_URI'].inspect}"
Rails.logger.info " [RAW_POST]: #{request.raw_post.inspect}"
Rails.logger.info " [PARAMS]: #{request.params.inspect}"
Rails.logger.info " [HTTP_AUTHORIZATION] #{request.headers['HTTP_AUTHORIZATION'].inspect}"
Rails.logger.info " [CONTENT_TYPE]: #{request.headers['CONTENT_TYPE'].inspect}"
Rails.logger.info " [HTTP_ACCEPT] #{request.headers['HTTP_ACCEPT'].inspect}"
Rails.logger.info " [HTTP_HOST] #{request.headers['HTTP_HOST'].inspect}"
Rails.logger.info " [HTTP_USER_AGENT] #{request.headers['HTTP_USER_AGENT'].inspect}"
@nesquena
nesquena / ruby_1_9_2
Created February 9, 2011 05:11
Install Ruby 1.9.2
$ sudo apt-get install gcc g++ build-essential libssl-dev libreadline5-dev zlib1g-dev linux-headers-generic
$ sudo apt-get install libc6-dev libssl-dev libmysql++-dev libsqlite3-dev make
$ wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p0.tar.gz
$ tar -xvzf ruby-1.9.2-p0.tar.gz
$ cd ruby-1.9.2-p0/
$ ./configure --prefix=/usr/local/ruby
$ make && sudo make install
$ sudo nano /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/ruby/bin"
@nesquena
nesquena / counter_backfill_migration.rb
Created November 17, 2010 21:13 — forked from mpakes/counter_backfill_migration.rb
Populate a cached counter field via a single SQL query.
# Credit to Mike Perham for this gem of an idea
# http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/
class RailsMigration < ActiveRecord::Migration
def self.up
add_column :media, :followers_count, :integer, :default => 0, :null => false
# Populate the media follower counter cache in one fell swoop.
sql = "update media, (select operable_id, count(*) as the_count from follow_operations "\
"group by operable_id) as follows set media.followers_count = follows.the_count "\
"where media.id = follows.operable_id;"
@nesquena
nesquena / tuning_ruby.txt
Created October 29, 2010 21:06
Performance Turning for REE
# http://www.rubyenterpriseedition.com/documentation.html#_garbage_collector_performance_tuning
# http://snaprails.tumblr.com/post/241746095/rubys-gc-configuration
# http://smartic.us/2010/10/27/tune-your-ruby-enterprise-edition-garbage-collection-settings-to-run-tests-faster/
# http://izumi.plan99.net/blog/wp-content/uploads/2009/01/ree-documentation.html#_garbage_collector_performance_tuning
$ sudo nano /usr/local/bin/tuned_ruby
# !/bin/bash 
export RUBY_HEAP_MIN_SLOTS=500000
export RUBY_HEAP_SLOTS_INCREMENT=250000
@nesquena
nesquena / application.js
Created October 1, 2010 23:56
Simple pattern for handling jquery js in rails
// public/javascripts/application.js
// JQUERY example
// Accepts ev.foo, ev.bar, ev.html
$(document).bind('some:event', function(ev) {
// do something here
$('some-div').html(ev.html);
});
@nesquena
nesquena / example_file.yml
Created September 10, 2010 01:04 — forked from trshafer/example_file.yml
TermInit Script
# you can make as many tabs as you wish...
# tab names are actually arbitrary at this point too.
---
- tab1: cd ~/foo/bar
- tab2:
- mysql -u root
- use test;
- show tables;
- tab3: echo "hello world"
- tab4: cd ~/baz/ && svn up