Skip to content

Instantly share code, notes, and snippets.

@eprothro
eprothro / heroku_postgresql_config_settings.md
Last active August 29, 2015 14:10
View Heroku Postgres configuration settings

Run PG:PSQL

With pg installed, you can run the pg:psql Heroku command to connect to your database and execute commands using the psql interactive terminal:

$ heroku pg:psql
psql (9.3.5, server 9.3.3)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.
database-name=> |
@eprothro
eprothro / gist:2b2a89fece090d0a1c43
Created February 24, 2015 19:28
Simple ruby memory benchmark
module Benchmark
def memory_usage
`ps -o rss= -p #{Process.pid}`.to_i
end
def memory
m0 = memory_usage
yield
memory_usage - m0
end
def kb
@eprothro
eprothro / gist:dc022de04c58291d5430
Last active August 29, 2015 14:16
QueryObject as Decorator for relation
class TestQuery < SimpleDelegator
  def initialize
    super(Bomb.all.extending(Scopes))
  end
  module Scopes
    def processed
      where(Bomb.arel_table[:asset_remote_url].eq(nil))
    end
 end
@eprothro
eprothro / gist:de0cb76631ccfb40b4a9
Last active August 29, 2015 14:21
Simple Object Oriented JS Example

Object Oriented Javascript Example

Consider a simple HTML element that we want to expand and contract by tapping a different target element.

<a href='expandable-element-1' data-expander>
  <!-- some link markup styled using an `expanded` class -->
</a>
@eprothro
eprothro / PEC Action Required
Created January 31, 2012 23:40
PEC Clean Water Action
Date: January 30, 2012
R.B. Sloan
Chief Executive Officer
Pedernales Electric Cooperative
P.O. Box 1
Johnson City, TX 78636
Dear PEC Bard Members and PEC Staff:
source :rubygems
gem 'rails', '3.1.2'
gem 'asset_sync', '~> 0.4.1'
gem 'awesome_print', '~> 1.0.2'
gem 'authorize-net', '~> 1.5.2'
gem 'cells', '~> 3.8.3'
gem 'countries', '~> 0.8.2'
gem 'dalli', '~> 2.0.4'
source :rubygems
gem 'rails', '3.1.2'
gem 'asset_sync', '~> 0.4.1'
gem 'awesome_print', '~> 1.0.2'
gem 'authorize-net', '~> 1.5.2'
gem 'cells', '~> 3.8.3'
gem 'countries', '~> 0.8.2'
gem 'dalli', '~> 2.0.4'
tddium suite
Looks like you haven't set up a suite on this computer for youversion-web/mobile...
Enter a repo name or press 'Return'. Using 'youversion-web' by default: 'youversion-web/mobile'
... Detected branch mobile
... Detected ruby ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin11.2.0]
... Detected bundle Bundler version 1.1.3
... Detected gem 1.8.15
>>> Tddium selects tests to run by default (e.g., in CI) by matching against a
list of Ruby glob patterns. Use "," to join multiple globs.

The problem

Exhibit A

class Record < ActiveRecord::Base
  validates_uniqueness_of :name
end

At some point, we realize we're performing an extra query to check uniqueness every time we validate the object.

Deadlock with Spring and cassandra_migrations

=> Rack::Timeout set to 1800 in development
Loading development environment (Rails 4.2.4)
[1] pry(main)> CassandraMigrations::Cassandra.client
=> #<Client:0x007ff17f6755e8
 @cluster=#<Cassandra::Cluster:0x3ff8bf4fc660>,
 @session=#<Cassandra::Session:0x3ff8bfb42574>,
 @sessions={:default=&gt;#, "timebomb_api_development"=&gt;#}&gt;