Skip to content

Instantly share code, notes, and snippets.

Avatar

Evan Prothro eprothro

View GitHub Profile
@eprothro
eprothro / heroku_postgresql_config_settings.md
Last active Aug 29, 2015
View Heroku Postgres configuration settings
View heroku_postgresql_config_settings.md

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 Feb 24, 2015
Simple ruby memory benchmark
View gist:2b2a89fece090d0a1c43
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 Aug 29, 2015
QueryObject as Decorator for relation
View gist:dc022de04c58291d5430
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 Aug 29, 2015
Simple Object Oriented JS Example
View gist:de0cb76631ccfb40b4a9

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>

<!-- unknown number of elements -->
@eprothro
eprothro / PEC Action Required
Created Jan 31, 2012
PEC Clean Water Action
View PEC Action Required
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:
View gist:2705416
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'
View gist:2705420
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'
View gist:2773124
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.
View interaction model motivation.md

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.

View cassandra_migrations and rails spring.md

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=>#<Cassandra::Session:0x3ff8bfb3a9a0>, "timebomb_api_development"=>#<Cassandra::Session:0x3ff8bfb42574>}>
You can’t perform that action at this time.