Skip to content

Instantly share code, notes, and snippets.

@r38y
r38y / class_method.rb
Last active August 29, 2015 13:57
View paths using the prepend_view_path class method vs instance method
#<ActionView::PathSet:0x007fc51b65c240 @paths=[#<ActionView::OptimizedFileSystemResolver:0x007fc513e22810 @pattern=":prefix/:action{.:locale,}{.:formats,}{.:handlers,}", @cache=#<ActionView::Resolver::Cache:0x007fc513e227e8 @data=#<ActionView::Resolver::Cache::SmallCache:0x007fc513e227c0 @backend={}, @default_proc=#<Proc:0x007fc51b545208@/Users/r38y/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/actionpack-4.0.3/lib/action_view/template/resolver.rb:48 (lambda)>>>, @path="/Users/r38y/Sites/bntp.bauernet.me/app/views/site_overrides/j-14.com">, #<ActionView::OptimizedFileSystemResolver:0x007fc51b54d4f8 @pattern=":prefix/:action{.:locale,}{.:formats,}{.:handlers,}", @cache=#<ActionView::Resolver::Cache:0x007fc51b54d4d0 @data=#<ActionView::Resolver::Cache::SmallCache:0x007fc51b54d4a8 @backend={}, @default_proc=#<Proc:0x007fc51b545208@/Users/r38y/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/actionpack-4.0.3/lib/action_view/template/resolver.rb:48 (lambda)>>>, @path="/Users/r38y/Sites/bntp.bauernet.me/app/views">]
@r38y
r38y / view_path_registry.rb
Last active August 29, 2015 13:57
Initializes a registry of view paths for the various themes in our apps.
# this is an initializer and used to set up various themes
# so we can use the same instances on each request
# I'm wondering if $path_set_registry should be a
# constant instead of a global variable
$path_set_registry = {}
Dir.entries('app/views/site_overrides').reject{|e| e.in?(['.', '..'])}.each do|domain|
paths = ["app/views/site_overrides/#{domain}"]
$path_set_registry[domain] = ActionView::PathSet.new(paths)
end

Keybase proof

I hereby claim:

  • I am r38y on github.
  • I am r38y (https://keybase.io/r38y) on keybase.
  • I have a public key whose fingerprint is 9C92 BD4F 93E3 2505 CC1E AB3F 6CDC BC3B A534 087B

To claim this, I am signing this object:

class NullPhoto
def file
@file = OpenStruct.new(
url: 'https://dossi-prod.s3.amazonaws.com/default-avatar.png'
)
end
# is this kosher?
def blank?
true
require 'spec_helper'
describe 'creating a person' do
it 'works with valid attributes' do
user = create(:user)
post "/api/people.json",
{ person: { name: 'Bob Johnson' } },
{ 'Authorization' => "Token token=#{user.authentication_token}" }
CREATE DATABASE new_clone WITH TEMPLATE old_database;
-- winning_count is a random number between 0 and 1
-- times the sum of the weights
SELECT id
FROM (
SELECT id, SUM(weight) OVER (ORDER BY id) S
FROM entries WHERE drawing_id = #{@drawing.id}
) Q
WHERE S >= winning_count
ORDER BY id
LIMIT 1;
@r38y
r38y / set_time_zone_back.rb
Last active August 29, 2015 14:04
Set timezone method that sets the time zone back after the request
class ApplicationController < ActionController::Base
around_action :set_timezone
def set_timezone
old_time_zone = Time.zone
Time.zone = current_user.time_zone
yield
ensure
Time.zone = old_time_zone
end
@r38y
r38y / no-promo.txt
Last active August 29, 2015 14:05
Databases not promoting
# HEROKU_POSTGRESQL_GREEN was the old master
# I promoted then got rid of the original master (because it was staging)
# noticed that the follower was still a follower
➜ twinit.bauernet.me git:(split-test) heroku pg:info -r staging
=== HEROKU_POSTGRESQL_MAROON_URL (DATABASE_URL)
Plan: Standard 2
Status: Available
Data Size: 7.76 GB
Tables: 16
@r38y
r38y / discussion.rb
Created January 11, 2015 01:52
Tokenable with settable token name
class Discussion < ActiveRecord::Base
include Tokenable
set_token_field_name :other_token_name
end