Skip to content

Instantly share code, notes, and snippets.

@zumbalogy
zumbalogy / gist:7806202
Last active December 30, 2015 08:59
No input validation, but yes to multi-stops
n = %w( Times_Square 34th 28th 23th Union_Square 8th )
l = %w( 8th 6th Union_Square 3rd 1st )
six = %w( Grand_Central 33rd 28th 23rd Union_Square Astor_Place )
q = %w( Times_Square Herald_Square Union_Square Canal_St )
puts "What train on? [n, l, six, q]"
on_train = gets.chomp
case on_train
when "n"
require './names'
total = 0
@names.sort.each_with_index do |name, index|
name_score = 0
a = name.upcase
a.each_byte do |byte|
name_score += (byte-64)
end
total += (name_score * index+1)
end
STARTING UP WITH RAILS Tunr App
$ rails new tunr_app -d postgresql -T
* update database.yml —> change default username to my username
* remove default index page —> $ rm public/index.html
$ rake db:create
@zumbalogy
zumbalogy / ruby uniq
Created August 3, 2014 18:54
uniq in ruby is funny stuff
[1,2,3].permutation {|v| p v if v.first.odd?}
[1, 2, 3]
[1, 3, 2]
[3, 1, 2]
[3, 2, 1]
# => [1, 2, 3]
[1,1,2,2,3,3].uniq
# => [1, 2, 3]
@zumbalogy
zumbalogy / gist:f8e17feaf719e52f0bcb
Created September 16, 2014 16:52
iOS Device Names
IOS_DEVICES = {
'iPhone1,1' => 'iPhone 1G',
'iPhone1,2' => 'iPhone 3G',
'iPhone2,1' => 'iPhone 3GS',
'iPhone3,1' => 'iPhone 4',
'iPhone3,3' => 'iPhone 4 (Verizon)',
'iPhone4,1' => 'iPhone 4S',
'iPhone5,1' => 'iPhone 5 (GSM)',
'iPhone5,2' => 'iPhone 5 (GSM+CDMA)',
'iPhone5,3' => 'iPhone 5C (GSM)',
stems = ARGF.read
.split
.each_cons(2)
.group_by(&:first)
def next_word(ary)
ary.sample[1]
end
e = Enumerator.new do |e|