Skip to content

Instantly share code, notes, and snippets.

@iamvery
iamvery / rails3.2-upgrade-issue.md
Created May 10, 2012 14:32
Issue I ran into upgrading rails 3.0 app to 3.2
has_many :related_whatevers,  :through => :whatever_relations,   :source => :related_whatever, :class_name => 'Whatever'

gives error

NameError: uninitialized constant WhateverRelationship::RelatedWhatever

when I try to add a "related_whatever". It seems to be ignoring the class_name option. This works fine under rails 3.0. Is it me or is this some kind of bug?


@iamvery
iamvery / activesupport_3.2.6_missing_require.txt
Created June 28, 2012 16:30
It appears that there is a require statement missing somewhere in ActiveSupport 3.2.6
$> pry
[1] pry(main)> require 'active_support/core_ext/numeric/time'
=> true
[2] pry(main)> 1.second.ago
=> 2012-06-28 11:25:21 -0500
[3] pry(main)> exit
$> gem install activesupport
Fetching: activesupport-3.2.6.gem (100%)
Successfully installed activesupport-3.2.6
@iamvery
iamvery / application_helper.rb
Created August 30, 2012 16:13
Shows how one might set a default will_paginate link renderer in a rails application
module ApplicationHelper
# This method is overriding the view helper provided by `will_paginate`
def will_paginate(collection_or_options = nil, options = {})
options, collection_or_options = collection_or_options, nil if collection_or_options.is_a? Hash
options.merge! :renderer => YourCustomLinkRenderer unless options[:renderer]
super *[collection_or_options, options].compact
end
end
@iamvery
iamvery / array_fuzzy_include.rb
Last active September 9, 2016 14:48
Check to see if an array includes any part of the given search value.
# %w(abd def ghi).fuzzy_include? 'definition' # => true
class Array
def fuzzy_include?(search_value, regex_format = '%s')
inject(false) do |is_found, array_value|
is_found or !!(search_value =~ /#{regex_format % array_value}/)
end
end
end
@iamvery
iamvery / postgresapp_unix_socket.md
Last active January 21, 2024 10:12
Setup Postgres.app to allow connection via unix socket

These are instructions to setup Postgres.app to allow connections over unix sockets. These instructions were written for Mac OS X 10.8 (Mountain Lion).

  1. Run Postgres.app once so that the configuration is initialized in ~/Library/Application Support/Postgres.
  2. Close Postgres.app
  3. Open ~/Library/Application Support/Postgres/var/postgresql.conf in your favorite text editor.
  4. Uncomment the line unix_socket_directory = '' and change it to unix_socket_directory = '/var/pgsql_socket'
  5. Create the directory /var/pgsql_socket if it doesn't exist.
  6. Run chmod 770 /var/pgsql_socket (may need to be run with sudo)
  7. Run chown root:staff /var/pgsql_socket (may need to be run with sudo)
jQuery(function($){
$(document).on('submit', 'form.prevent-multiple-submissions', function(e){
$(this).find(':submit').attr('disabled', true);
})
});
require 'base64'
class SnapshotsController < AuthenticatedController
protect_from_forgery except: :create
def create
chart1 = snapshot.split(',')
image = Base64.decode64(chart1[1])
file = File.open("/tmp/test.png", 'wb') do|f|
var GRID_WIDTH = 10
var GRID_HEIGHT = 8
function random_between(start, end){
Math.round(Math.random() * (end - start)) + start
}
function randomly_select_bead() {
random_x = random_between(0, GRID_WIDTH)
random_y = random_between(0, GRID_HEIGHT)
1.9.3p448 :001 > SOME_CONSTANT_HASH = { abc: 123 }
=> {:abc=>123}
1.9.3p448 :002 > SOME_CONSTANT_HASH[:abc]
=> 123
1.9.3p448 :003 > SOME_CONSTANT_HASH[:abc] = 456
=> 456
1.9.3p448 :004 > SOME_CONSTANT_HASH
=> {:abc=>456}
1.9.3p448 :005 > SOME_FROZEN_CONSTANT_HASH = { abc: 123 }.freeze
=> {:abc=>123}
master ● » be rake db:reset && be rspec
PG::ObjectInUse: ERROR: database "test_app_development" is being accessed by other users
DETAIL: There is 1 other session using the database.
: DROP DATABASE IF EXISTS "test_app_development"
/Users/jay/Github/rails/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `exec'
/Users/jay/Github/rails/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `block in execute'
/Users/jay/Github/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:434:in `block in log'
/Users/jay/.rvm/gems/ruby-2.0.0-p195/bundler/gems/rails-25649c7fd742/activesupport/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/jay/Github/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:428:in `log'
/Users/jay/Github/rails/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in `execute'