Skip to content

Instantly share code, notes, and snippets.

@timothyandrew
timothyandrew / output.png
Created September 12, 2011 17:32
Codebrawl #10
output.png
@timothyandrew
timothyandrew / fbuzz.rb
Created September 16, 2011 15:04
FizzBuzz
#!/usr/bin/env ruby
for i in 1..100
if(i % 5 == 0 and i % 3 == 0)
puts "FizzBuzz"
elsif(i % 3 == 0)
puts "Fizz"
elsif(i % 5 == 0)
puts "Buzz"
else
@timothyandrew
timothyandrew / README.md
Created October 12, 2011 13:29
Number in 'Words'

README

  • This ruby script converts a number to it's text form. For example, 542 is five hundred and forty two.

  • Use the download button above to grab a copy.

  • This requires a ruby version > 1.9

$ ruby -v 

README

Solve the XKCD Bridge puzzle

$ ./bridge-test.rb
Loaded suite ./bridge-test
Started
C and D crossed over in 2 minutes.
D crossed back in 1 minutes.
@timothyandrew
timothyandrew / remspc.rb
Created October 14, 2011 11:37
remove spaces
#!/usr/bin/env ruby
str = " this is some text with spaces in it "
puts str.split.join
#Output: thisissometextwithspacesinit
@timothyandrew
timothyandrew / image.png
Created November 18, 2011 16:31
Instagram Engineering Challenge
image.png
@timothyandrew
timothyandrew / inv_fizzbuzz.rb
Created May 5, 2012 07:27
Inverse Fizzbuzz
def fizzbuzz(n)
str = ""
str << (n % 3 == 0 ? "fizz" : "")
str << (n % 5 == 0 ? "buzz" : "")
end
list = ["fizz", "fizz", "buzz"]
arr = (1..100).map { |n| [n, fizzbuzz(n)] }.reject { |h| h.last.empty? }
res = arr.each_slice(list.length).to_a.find_all do |slice|
@timothyandrew
timothyandrew / bootstrap_zsh.sh
Created July 18, 2012 18:43
Vagrant Setup Shell Script
#ZSH
echo "installing zsh"
sudo apt-get install -y zsh
#Git
echo "installing git"
sudo apt-get install -y git-core
#Oh My Zsh
echo "installing oh-my-zsh"
@timothyandrew
timothyandrew / moth_podcast_scrape.rb
Created September 19, 2012 20:53
Scrape (links for) archived episodes of the Moth Podcast from podcast-directory.co.uk
require 'rubygems'
require 'mechanize'
def fetch_podcast_links_from_index_page(index_link)
agent = Mechanize.new
agent.get(index_link)
story_links = agent.page.links.find_all { |l| l.text.include? ':' }
story_links.map do |link|
link.click
class Chest
attr_reader :type, :index, :keys
def initialize(array, index)
@type = array.shift.to_i
@keys = array.shift(array.shift.to_i).map(&:to_i)
@index = index
end
def unlock
@keys