Skip to content

Instantly share code, notes, and snippets.

ordered_ids = [5,2,3,1,4] # some array of ordered ids
records = Record.find(ordered_ids) # find the records that go with the ordered_ids
# loop the records and store them in a temp hash
temp_hash = {}
records.each do |record|
temp_hash[record.id] = record
end
# convert the temp_hash into a new array
@yellow5
yellow5 / cucumber + thinking_sphinx + devise digging
Created January 11, 2011 17:52
Some info related to the exploration of errors in cucumber when including thinking_sphinx indexes and devise as the authentication system
I think our problem is related to this: http://www.lostincode.net/blog/testing-devise-controllers
The test is consistently failing just loading the root path with...
ActionController::UnknownAction (ActionController::UnknownAction)
/Users/cameron/.rvm/gems/ree-1.8.7-2010.02@ch-admin/gems/devise-1.0.9/lib/devise/controllers/internal_helpers.rb:65:in `is_devise_resource?'
So, why not investigate what the method has? The method is in 'gems/devise-1.0.9/lib/devise/controllers/internal_helpers.rb:64
def is_devise_resource? #:nodoc:
@yellow5
yellow5 / ip_conversion_tools.rb
Created February 2, 2011 21:15
Meant for a rails controller; provides actions to convert ipv4 addresses to integers and vice versa
module IpConversionTools
def self.included(base)
base.class_eval do
helper_method :ip_to_i
helper_method :ip_to_s
end
end
protected
def ip_to_i(ip=nil)
@yellow5
yellow5 / sample_foreigner_usage_spec.rb
Created February 11, 2011 21:20
An example way to verify that a foreigner key is created for your model
context "foreign keys" do
def foreign_key_definition_to(to_table, options={})
defaults = { :primary_key => "id", :column => "#{to_table.singularize}_id" }
defaults[:name] = "#{subject.class.table_name}_#{defaults[:column]}_fk"
options = defaults.merge(options)
Foreigner::ConnectionAdapters::ForeignKeyDefinition.new(subject.class.table_name, to_table, options)
end
it "should include some_model_records with dependent delete" do
subject.connection.foreign_keys(subject.class.table_name).should include(foreign_key_definition_to("some_model_records", { :dependent => :delete }))
@yellow5
yellow5 / rvm_ree_upgrade
Created February 14, 2011 14:27
Line to add to ~/.rvm/config/user if you want REE 1.8.7-2011.01 right now...
ree_1.8.7_url=http://rubyenterpriseedition.googlecode.com/files/ruby-enterprise-1.8.7-2011.01.tar.gz
@yellow5
yellow5 / ajax_snip.js
Created February 15, 2011 15:15
A way to pass along csrf meta tag with Ajax requests
$.ajaxSetup({
'beforeSend': function(xhr) { xhr.setRequestHeader('X-CSRF-Token', $("meta[name='csrf-token']").attr('content')); }
});
@yellow5
yellow5 / mysql_snip.sql
Created February 17, 2011 21:35
An example of a quick way to list tables in a database containing a given column name
select table_name
from `information_schema`.`columns`
where table_schema = 'DB_NAME' and column_name = 'DESIRED_COLUMN_NAME';
@yellow5
yellow5 / ree_2011.03_install.log
Created February 26, 2011 15:44
Installation log of ree-1.8.7-2011.03 via rvm
cameron@cam-macbook-pro:~/.rvm/log$ cat /Users/cameron/.rvm/log/ree-1.8.7-2011.03/install.log
[2011-02-26 09:33:21] ./installer -a $/ree-1.8.7-2011.03 --no-tcmalloc --dont-install-useful-gems -c --with-readline-dir=/Users/cameron/.rvm/usr
Welcome to the Ruby Enterprise Edition installer
This installer will help you install Ruby Enterprise Edition 1.8.7-2011.03.
Don't worry, none of your system files will be touched if you don't want them
to, so there is no risk that things will screw up.
You can expect this from the installation process:
1. Ruby Enterprise Edition will be compiled and optimized for speed for this
@yellow5
yellow5 / gist:1029236
Created June 16, 2011 13:35
debian wheezy libgnutls26
cameron@cam-debian:~$ aptitude show libgnutls26
Package: libgnutls26
State: installed
Automatically installed: no
Version: 2.10.5-1+b1
Priority: standard
Section: libs
Maintainer: Debian GnuTLS Maintainers <pkg-gnutls-maint@lists.alioth.debian.org>
Uncompressed Size: 1,323 k
Depends: libc6 (>= 2.3), libgcrypt11 (>= 1.4.6), libtasn1-3 (>= 1.6-0), zlib1g (>= 1:1.1.4)
@yellow5
yellow5 / gist:1029333
Created June 16, 2011 14:32
libssl installations on debian wheezy
cameron@cam-debian:~$ aptitude search libssl
p libcherokee-mod-libssl - Cherokee web server - SSL crypto functions plugin
i libssl-dev - SSL development libraries, header files and documentation
i A libssl-doc - SSL development documentation documentation
p libssl-ocaml - OCaml bindings for OpenSSL (r