This file contains 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
#prints numbers 1-100 | |
#when the number is divisible by 3, say fizz | |
#when the number is divisible by 5 say buzz | |
#when the number is divisible by 3 and 5 say fizzbuzz | |
i = 1 | |
while i < 101 | |
if i % 3 == 0 | |
puts "fizz" | |
elsif i % 5 == 0 |
This file contains 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
(1..100).each do |x| | |
m3 = x.modulo(3) == 0 | |
m5 = x.modulo(5) == 0 | |
puts case | |
when (m3 and m5) then 'FizzBuzz' | |
when m3 then 'Fizz' | |
when m5 then 'Buzz' | |
else x | |
end |
This file contains 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 Artist | |
#attr_accessor is ruby magic that transforms instance variables into reader & writer methods (see lines 14-22) | |
attr_accessor :name, :songs | |
ARTISTS = [] | |
def initialize | |
@name = name | |
@songs = [] | |
#for each instance of the class artist we instantiate(self), we push it into the ARTISTS array via the shovel method. |
This file contains 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
#assign .srt file string to a variable | |
string = "00:03:10,500 --> 00:00:13,000" | |
#write regex to betak string into its constitute timecode parts and assign it to var reg_time | |
#captured data is anything between the parentheses | |
#'?<>' syntax assigns a key to each snapshot of data, e.g., '?<hour1>' assigns the key hour1 | |
reg_time = /(?<hour1>.*):(?<minutes1>.*):(?<seconds1>.*)--> (?<hour2>.*):(?<minutes2>.*):(?<seconds2>.*)/ | |
#call .match method on reg_time, passing it the string as parameter to retreive the data captures | |
m = reg_time.match(string) |
This file contains 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 Compliment | |
attr_accessor :message, :image, :color | |
COMPLIMENTS = ["You're pretty", "You're super-fantastic!"] | |
IMAGES = ["https://24.media.tumblr.com/cc65a152ab08459fde8e834b30f795a7/tumblr_mxis6kDogx1qdhrnoo1_250.gif", "https://24.media.tumblr.com/b1229bb51705118a2e0be539db74df71/tumblr_mxao3oRohX1sbf1g1o1_500.gif", "http://www.mycathatesyou.com/wp-content/gallery/gifs/6.gif"] | |
COLORS = ["#8C727B", "#8CBEB2", "F2EBBF", "#F3B562", "#F76363"] | |
HISTORY = [] | |
def initialize |
This file contains 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 Compliment | |
attr_accessor :message, :image, :color | |
COMPLIMENTS = ["You're pretty", "You're super-fantastic!"] | |
IMAGES = ["image1", "image2", image3", "image4"] | |
COLORS = ["#8C727B", "#8CBEB2", "F2EBBF", "#F3B562", "#F76363"] | |
HISTORY = [] | |
def initialize |
This file contains 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
module ComplimentSite | |
class App < Sinatra::Application | |
enable :sessions | |
get '/' do | |
if session[:last_color].nil? && session[:last_message].nil? | |
@compliment = Compliment.new | |
session[:last_color] = @compliment.color | |
session[:last_message] = @compliment.message | |
else | |
@compliment = Compliment.new |
This file contains 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
>>> 3+2 | |
5 | |
>>> typeof(3); | |
number | |
>>> typeof(3) === typeof(4.32); | |
true | |
>>> 5/0 |
This file contains 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
//this function finds the absolute value of a number | |
function absolute(num) { | |
if (num < 0) { | |
return -num; | |
} else { | |
return num; | |
} | |
} |
This file contains 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
function absolute(num) { | |
if (num < 0) { | |
return -num; | |
} else { | |
return num; | |
} | |
} | |
console.log(absolute(-10)); |
OlderNewer