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
$(document).ready(function() { | |
$.validator.addMethod("capLetsRegex", function(value) { | |
return /[A-Z]+/.test(value); | |
}, "Password must contain at least one capital letter."); | |
$.validator.addMethod("includeNumeric", function(value) { | |
return /[0-9]+/.test(value); | |
}, "Password must contain at least one number."); | |
$.validator.addMethod("emailRegex", function(value) { |
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
<!doctype html> | |
<html> | |
<head> | |
<link rel="stylesheet" href="http://cdn.jsdelivr.net/normalize/2.1.0/normalize.css"> | |
<link rel="stylesheet" href="main.css"> | |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800"> | |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Lato:100,900"> | |
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.0.2/css/font-awesome.min.css"> | |
</head> |
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
/* Here is your chance to take over Socrates! | |
Spend 10 minutes on each of the following hacks to the Socrates website. | |
Enter them in the console to make sure it works and then save | |
your results here. | |
Choose a new pair for each. Add your names to the section you complete. | |
*/ |
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
# recursive but with Array#each | |
def flatten(array) | |
return [array] unless array.is_a?(Array) | |
result = [] | |
array.each do |x| | |
result += flatten(x) | |
end | |
result |
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
def small_num_to_english(n) | |
# n needs to be < 1000 | |
if n % 100 == 0 | |
["zero", "one hundred", "two hundred", "three hundred", "four hundred", | |
"five hundred", "six hundred", "seven hundred", "eight hundred", "nine hundred"][n/100] | |
elsif n >= 0 && n <= 19 | |
%w(zero one two three four five six seven eight nine ten eleven | |
twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen)[n] | |
elsif n % 10 == 0 && n < 100 | |
%w(zero ten twenty thirty forty fifty sixty seventy eighty ninety hundred)[n/10] |
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 GuessingGame | |
attr_reader :init_guess | |
def initialize(guess) | |
@init_guess = guess | |
@solved = false | |
end | |
def guess(guess) |
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 GuessingGame | |
attr_reader :init_guess | |
attr_accessor :solved | |
def initialize(guess) | |
@init_guess = guess | |
@solved = false | |
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
def mode(array) | |
count = Hash.new(0) # specify default object to 0, because you can't += 1 to nil. | |
array.each { |elem| count[elem] += 1 } | |
count.keep_if { | key, val | val == count.values.max }.keys | |
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
def is_fibonacci?(i) | |
a = 0 | |
b = 1 | |
while true | |
c = a + b | |
return true if c == i # the more I look at this... it's a little iffy and should be redone. | |
return false if c > i | |
a,b = b, c # eval right assign left...'b' (r) is assigned to 'a'(l), 'c'(r) is assigned to 'b'(l) | |
end | |
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 RPNCalculator | |
def evaluate(str) | |
ary = [] | |
str.split.each do |i| | |
if i.match(/\d/) | |
ary << i.to_i | |
elsif i.match(/\-|\+|\*/) | |
operator = i.to_sym | |
ary << ary.pop(2).inject(operator) | |
end |