Skip to content

Instantly share code, notes, and snippets.

View charmainetham's full-sized avatar

Charmaine Tham charmainetham

View GitHub Profile

Keybase proof

I hereby claim:

  • I am charmainetham on github.
  • I am charmainetham (https://keybase.io/charmainetham) on keybase.
  • I have a public key whose fingerprint is 91FA CA93 B948 9B0B 5726 3852 ADC3 BEC5 1663 209E

To claim this, I am signing this object:

@charmainetham
charmainetham / event.html
Created May 31, 2016 12:34
event handling examples
<!DOCTYPE html>
<html>
<head></head>
<body>
<form>
First name:<br>
<input type="text" name="firstname"><br>
Last name:<br>
<input type="text" name="lastname">
</form>
@charmainetham
charmainetham / arroflight.js
Created May 31, 2016 12:05
Array Of Light
function arrayOfLight(n){
var arr =[]
for(var i = 0; i <= n; i ++){
arr.push(i)
};
return arr
};
arrayOfLight(5)
@charmainetham
charmainetham / debugging.js
Created May 31, 2016 11:58
Debugging exercises
//Why is this broken?
var mySuperAwesomeVariableName = "Ted Mosby";
mySuperAwesomeVariableName = "BATMAN!";
console.log(mySuperAwesomeVariableName);
//line breaks are interpreted as line-ending semicolons.
//Even in a string,if you include a hard line break in between quotes you’ll get a parse error (unterminated string).
//backslashes are the way to go
#NUMBER 1
SELECT e.isbn FROM editions AS e
JOIN publishers AS p ON e.publisher_id = p.id
WHERE p.name = 'Random House';
#NUMBER 2 NUMBER 3 NUMBER 4, NUMBER 5
SELECT b.title, e.isbn, s.stock, s.retail,
@charmainetham
charmainetham / benchmark.rb
Created April 30, 2016 20:22
benchmark with blocks
def benchmark
starting_time = Time.now
yield
end_time = Time.now
end_time - starting_time
end
# Be careful, pasting this into IRB will take a long time to print.
# It's a loooong string. :)
long_string = "apple"*100000000
@charmainetham
charmainetham / popbottle.rb
Created April 30, 2016 04:59
pop bottles
# 2 empty empty bottles you get one free bottle
# for every 4 bottle caps you get one free bottle
# each bottle cost $2
def calculate(number)
empty_bottles(number) + bottle_caps(number)
end
def bottles_from_cash(cashtobottles)
@no_of_bottles = cashtobottles/2
@charmainetham
charmainetham / candidates.rb
Created April 29, 2016 18:48
Candidates assignment
require 'active_support/all'
@candidates = [
{
id: 5,
years_of_experience: 4,
github_points: 293,
languages: ['C', 'Ruby', 'Python', 'Clojure'],
date_applied: 5.days.ago.to_date,
age: 26
@charmainetham
charmainetham / regex.rb
Created April 29, 2016 00:44
Regular Expressions
# Determine whether a string contains a SIN (Social Insurance Number).
# A SIN is 9 digits and we are assuming that they must have dashes in them
def has_sin?(string)
if /\W\d{3}-\d{3}-\d{3}$/.match string
return false
else
return true
end
end
@nums = { "M"=>1000, "D"=>500, "C"=>100, "L"=>50, "X" =>10, "V" =>5, "I" =>1}
def to_roman(number)
roman = ""
@nums.each do |rom,num|
while number >= num
roman << rom
number -= num # TODO update number to take remainder
end