Skip to content

Instantly share code, notes, and snippets.

@arn-e
arn-e / music_service_routes_2.rb
Created November 15, 2012 19:49
Music Service 2
MusicService::Application.routes.draw do
resources :albums
resources :artists
resources :songs
match ':artist_name(/:album_name(/:song_name))' => 'artists#search_by_multiple_criteria'
end
@arn-e
arn-e / catch_all_routes.rb
Created November 15, 2012 19:00
routes catch all
MusicService::Application.routes.draw do
resources :albums
resources :artists
resources :songs
match ':artist_name' => 'artists#search_by_artist'
end
myArray = [1,2,3,4,5];
mySecondArray = [1,2,3,4,5];
myThirdArray = [1,2,3,9,5];
Array.prototype.isEqualTo = function ( compareTo ) {
if ( this.length !== compareTo.length ) return false;
for ( var i = 0; i < this.length; i ++ ){
if ( this[i] !== compareTo[i] ) return false;
}
return true;
@arn-e
arn-e / array_comparison_2.js
Created November 12, 2012 07:36
Array Comparison 2
> myArray = [1,2,3,4,5]
[ 1, 2, 3, 4, 5 ]
> myArrayCopy = myArray;
[ 1, 2, 3, 4, 5 ]
> myArray === myArrayCopy;
true
@arn-e
arn-e / array_comparison_1.js
Created November 12, 2012 07:34
JS Array Comparison
> myArray = [1,2,3,4,5]
[ 1, 2, 3, 4, 5 ]
> mySecondArray = [1,2,3,4,5]
[ 1, 2, 3, 4, 5 ]
> myArray === mySecondArray;
false
@arn-e
arn-e / shakespeare.rb
Created November 5, 2012 06:27
shakes
require 'twitter'
require 'tweetstream'
require 'pp'
require 'csv'
class TwitterResponder
def initialize
@shakes = CSV.read('shakespeare.csv')
Twitter.configure do |config|
@arn-e
arn-e / diagonals_scratch.rb
Created November 1, 2012 18:16
find_diagonals_scratch
#test array
class TestArray
def initialize
@array = Array.new(6).map{|i| Array.new(7)}
# populate_fields
populate_fields_numeric
end
@arn-e
arn-e / array_reversed
Created November 1, 2012 04:26
array reversal with coordinates
["0, 0", "0, 1", "0, 2", "0, 3", "0, 4", "0, 5", "0, 6"]
["1, 0", "1, 1", "1, 2", "1, 3", "1, 4", "1, 5", "1, 6"]
["2, 0", "2, 1", "2, 2", "2, 3", "2, 4", "2, 5", "2, 6"]
["3, 0", "3, 1", "3, 2", "3, 3", "3, 4", "3, 5", "3, 6"]
["4, 0", "4, 1", "4, 2", "4, 3", "4, 4", "4, 5", "4, 6"]
["5, 0", "5, 1", "5, 2", "5, 3", "5, 4", "5, 5", "5, 6"]
["5, 0", "5, 1", "5, 2", "5, 3", "5, 4", "5, 5", "5, 6"]
["4, 0", "4, 1", "4, 2", "4, 3", "4, 4", "4, 5", "4, 6"]
["3, 0", "3, 1", "3, 2", "3, 3", "3, 4", "3, 5", "3, 6"]
@arn-e
arn-e / sqlite_sample.rb
Created October 30, 2012 05:05
sqlite sample
require 'csv'
require 'sqlite3'
class CongressMembers
def initialize
@list = []
@db = SQLite3::Database.new "test.db"
CSV.foreach("politicians.csv", :headers => :first_row, :header_converters => :symbol) do |row|
@list << Politician.new(row[:name], row[:party], row[:location], row[:grade_level_since_1996], row[:grade_level_112th_congress], row[:years_in_congress], row[:dw1_score])
@arn-e
arn-e / un_abridged_code.rb
Created October 29, 2012 01:12
un abridged code.rb
def binary_search(item,array,min = 0,max = array.length, half = (min + max) / 2)
return min if item == array[min]
return -1 if (item < array[0] || item > array[array.length-1]) || (min == max - 1)
item < array[half] ? binary_search(item,array,min,half) : binary_search(item,array,half,array.length)
end
def prime_factors(n, factors = [], f = 2)
return factors.push(f) if n == f
n % f == 0 ? prime_factors(n / f, factors.push(f)) : prime_factors(n, factors, f + 1)
end