Skip to content

Instantly share code, notes, and snippets.

@alekst
alekst / gist:11255016
Last active August 29, 2015 14:00
test verbose's truthiness
# vim:fileencoding=utf-8
require_relative 'test_helper'
context 'Resque::Scheduler::Configuration' do
test 'verbose should be false' do
assert_kind_of(FalseClass, Resque::Scheduler.verbose)
end
end
@alekst
alekst / heroku
Last active August 29, 2015 13:56
$ heroku -v
dyld: lazy symbol binding failed: Symbol not found: _ruby_run
Referenced from: /usr/local/bin/ruby
Expected in: /usr/lib/libruby.dylib
dyld: Symbol not found: _ruby_run
Referenced from: /usr/local/bin/ruby
Expected in: /usr/lib/libruby.dylib
Trace/BPT trap: 5
grid = Hash[("A".."Z").to_a.zip(1..27).to_a] # creates a hash where keys are letters, values are numbers.
def to_numbers
map {|i| grid.fetch(i)} #converts array of letters to numbers, using grid hash.
end
def to_letters
sum.map {|i| grid.key(i)} #convers array of numbers into letters, using grid hash.
end
class Numeric # converts numbers into letters
Alph = ("A".."Z").to_a
def alph
s, q = "", self
(q, r = (q - 1).divmod(26)) && s.prepend(Alph[r]) until q.zero?
s
end
end
class Numeric # converts numbers into letters
Alph = ("A".."Z").to_a
def alph
s, q = "", self
(q, r = (q - 1).divmod(26)) && s.prepend(Alph[r]) until q.zero?
s
end
end
@alekst
alekst / gist:8650152
Created January 27, 2014 15:14
unless
irb(main):001:0> array = ["a", "b", "c"]
=> ["a", "b", "c"]
irb(main):002:0> unless array[0] == "b"
irb(main):003:1> array << "d"
irb(main):004:1> end
=> ["a", "b", "c", "d"]
irb(main):005:0>
@alekst
alekst / phone-number.rb
Created September 9, 2013 19:46
A code submitted to exercism.io as a solution to the phone number tests.
class PhoneNumberTest < MiniTest::Unit::TestCase
class PhoneNumber
def initialize(number)
@number = number
end
def number
number = @number.gsub(/[^0-9]/i, '')
validates(number)
@alekst
alekst / dna.rb
Created September 9, 2013 15:34
a code to find the number of different links in two strands of DNA. Done for exercism.io.
class DNATest < MiniTest::Unit::TestCase
class DNA
def initialize(strand) #initializes the original strand
@strand = strand
end
def hamming_distance(sample) # compares it to sample
0 if sample.empty? # returns 0 if sample DNA is empty
@strand = split(@strand) # splits the orginal DNA strand into an array
sample = split(sample) # splits the sample DNA strand into an array
@alekst
alekst / dna.rb
Created September 6, 2013 15:40 — forked from shepmaster/dna.rb
class DNATest < MiniTest::Unit::TestCase
# You don't have to put your classes inside of the test case, but it
# doesn't hurt for these examples
class DNA
def initialize(string)
@string = string
# You can provide a default value for hashes. This also avoids
# hardcoding the letters here.
@counts = Hash.new(0)
@alekst
alekst / dna.rb
Last active December 22, 2015 11:09
class DNATest < MiniTest::Unit::TestCase
class DNA
def initialize(string)
@string = string
@counts = {"A"=> 0, "T" => 0, "C"=> 0, "G"=> 0}
dna_validation
end
def count(element)