This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fizz Buzz | |
# Print the numbers from 1 to 100 | |
# If a number is divisible by 3 print "Fizz" instead | |
# If a number is divisible by 5 print "Buzz" instead | |
# If a number is divisible by 3 and 5 print "FizzBuzz" instead | |
# Sample output | |
# 1 | |
# 2 | |
# Fizz | |
# 4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# write a recursive function that brings back a factorial | |
# | |
# How does factorial work: | |
# 0! = 1 #=> 1 | |
# 1! = 1 #=> 1 | |
# 2! = 2 * 1 #=> 2 | |
# 3! = 3 * 2 * 1 #=> 6 | |
# 4! = 4 * 3 * 2 * 1 #=> 24 | |
# 5! = 5 * 4 * 3 * 2 * 1 #=> 120 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write a url shortener application in Rails. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write a url shortener application in Rails. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How would you write an erb file that produces exactly the following output | |
<articles> | |
<article>Title</article> | |
<article>Title</article> | |
<article class=”high”>Title</article> | |
<article>Title</article> | |
<article>Title</article> | |
<article class=”high”>Title</article> | |
<article>Title</article> | |
<article>Title</article> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Given the following hash | |
h = {a: 1, b1: {b2: {b3: nil}, c2: nil}, c1: {c2: {c3: nil}}} | |
# Write a function that prints out all the keys |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Given the following array: | |
# assume ruby 1.9+ | |
array = [1,2,3,4,5,6,7,8,9,10] | |
# You want to print them out like so | |
# [first, last] | |
# [first, rest] | |
# [first, rest minus last, last] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# There are 2 robots placed on an infinitely wide 2 dimensional line. | |
# The robots can’t see each other. | |
# Each robot has 1 marker to the right but 1 of them doesn’t have one on the left. | |
# - unit of distance | |
# ^ marker | |
# ~ indefinite amount of units of distance | |
# ---~---(Robot)---~---^---~---(Robot)---~--^---~--- | |
# Write a program that will make that 2 robots collide using the following Robot Api: | |
# move_left(n) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
require 'json' | |
def get(key) | |
lambda { |s| s[key].empty? ? nil : s[key] } | |
end | |
# ["title", "abstract", "name", "bio", "starts_at", "ends_at", "category", "room"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PaymentProxy | |
def initialize(gateway) | |
@gateway = gateway | |
@observers = [] | |
end | |
def register_observer(o) | |
# ... | |
end | |