Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Damian Esteban damianesteban

🎯
Focusing
View GitHub Profile
View SuperManIdentityTest.swift
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 Aug 28, 2015
MultiplesOfThreeAndFive
View multiples.swift
// 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
View remote.rb
# test from iGist app
puts "Hello Underworld"
View keybase.md

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:

View sub_sad_solved.rb
# 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 Apr 5, 2014
v 0.01 of a Movie Database Application written in Ruby.
View movies_database.rb
# 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"
View keybase.md

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
fibonacci sequence with yield
View fib_up_to.rb
# 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
basic fibonacci sequence print out
View fib_sequence.rb
# 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|
View arrays_and_strings.rb
array = ["Ruby", "Pascal", "Smalltalk", "io"]
# And then we want to return the value at Index 1:
array[1]
# vs.
puts array[1]