Skip to content

Instantly share code, notes, and snippets.

View tlands's full-sized avatar

Thomas Landon tlands

  • TaskRabbit
  • San Diego, California
View GitHub Profile
@tlands
tlands / form-validator.js
Last active December 22, 2015 10:19 — forked from ksolo/form-validator.js
Form Validation NEED TO REDO THIS OO STYLE ;)
$(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) {
@tlands
tlands / index.html
Created September 3, 2013 05:13 — forked from dbc-challenges/index.html
DBC Phase 2 Practice Assessment Part 3
<!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>
/* 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.
*/
@tlands
tlands / flatten.rb
Last active December 19, 2015 18:09
Recursively flatten an array. First uses Array#each, second uses no iteration. Both only use one arg. (First attempt I posted actually called my first method... so it was undoubtedly incorrect as far as no iteration goes. This one's right though.)
# 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
@tlands
tlands / an_unwieldy_mess.rb
Last active December 19, 2015 14:49
I more or less brute forced the sh!t out of this... Any thoughts to make it tighter/lighter? Also, is this an example of a tail recursive function because nothing is changed after the recursive call, just printed?
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]
class GuessingGame
attr_reader :init_guess
def initialize(guess)
@init_guess = guess
@solved = false
end
def guess(guess)
class GuessingGame
attr_reader :init_guess
attr_accessor :solved
def initialize(guess)
@init_guess = guess
@solved = false
end
@tlands
tlands / array_mode.rb
Created June 26, 2013 02:57
Finding the mode of an array
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
@tlands
tlands / fibonacci.rb
Created June 24, 2013 17:10
Fibonacci numbers : True or False
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
@tlands
tlands / RPNcalulator.rb
Last active December 18, 2015 12:49
Here's a Ruby version of RPN calculator.
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