Skip to content

Instantly share code, notes, and snippets.

View damianesteban's full-sized avatar
🎯
Focusing

Damian Esteban damianesteban

🎯
Focusing
View GitHub Profile
@damianesteban
damianesteban / SuperManIdentityTest.swift
Created August 27, 2015 15:29
Test for Superman in Swift 2
enum SuperManIdentityError: ErrorType {
case WrongSecretIdentityError
}
func isSuperManTest(testWithSecretIdentity secretIdentity: String) throws -> String {
if secretIdentity != "Clark Kent" {
throw SuperManIdentityError.WrongSecretIdentityError
}
return secretIdentity
}
@damianesteban
damianesteban / multiples.swift
Created August 28, 2015 17:56
MultiplesOfThreeAndFive
// Ghetto Way
var numbers : [Int] = []
func multiplesOfThreeAndFive(range1: Int, range2: Int) -> Int {
for i in range1..<range2 {
if i % 3 == 0 || i % 5 == 0 {
numbers.append(i)
}
}
let sumOfMultiples = numbers.reduce(0, combine: +)
return sumOfMultiples
# test from iGist app
puts "Hello Underworld"

Keybase proof

I hereby claim:

  • I am estebanrules on github.
  • I am estebanrules (https://keybase.io/estebanrules) on keybase.
  • I have a public key whose fingerprint is 1EDD E685 401E 3121 D5D5 68E7 F959 72A8 98F0 409F

To claim this, I am signing this object:

# Given a string, replace every instance of sad to happy
#
# add_more_ruby("The clowns were sad.") # => "The clowns were happy."
# add_more_ruby("The sad dad said sad stuff.") # => "The happy dad said happy stuff."
# add_more_ruby("Sad times are ahead!") # => "Happy times are ahead!"
def add_more_ruby(string)
string.gsub(/[sS]ad/, 'sad' => 'happy', 'Sad' => 'Happy')
end
@damianesteban
damianesteban / movies_database.rb
Created April 5, 2014 18:07
v 0.01 of a Movie Database Application written in Ruby.
# First, make a Hash with a title of a movie, give it a rating.
movies = Hash.new
puts "What would you like to do?"
choice = gets.chomp
case choice
when "add"

Keybase proof

I hereby claim:

  • I am estebanrules on github.
  • I am estebanrules (https://keybase.io/estebanrules) on keybase.
  • I have a public key whose fingerprint is C9A8 21E3 1A3A 8C19 B498 019F C98D D0C0 156B 670D

To claim this, I am signing this object:

@damianesteban
damianesteban / fib_up_to.rb
Created May 6, 2014 05:52
fibonacci sequence with yield
# Fibonacci sequence with yield / parallel assignment
def fib_up_to(max)
i1, i2, = 1, 1 # parallel assignment
while i1 <= max
yield i1
i1, i2 = i2, i1 + i2
end
end
fib_up_to(1000) { |f| print f, " " }
@damianesteban
damianesteban / fib_sequence.rb
Created May 6, 2014 05:58
basic fibonacci sequence print out
# Outputs a Fibonacci sequence, the length of the sequence being determined by the user.
puts "How many numbers from the sequence would you like to see?"
a = gets.chomp.to_i
def fib(n)
return n if (0..1).include? n
fib(n-1) + fib(n-2) if n > 1
end
a.times do |i|
@damianesteban
damianesteban / arrays_and_strings.rb
Created June 25, 2014 17:06
Arrays and Strings
array = ["Ruby", "Pascal", "Smalltalk", "io"]
# And then we want to return the value at Index 1:
array[1]
# vs.
puts array[1]