Skip to content

Instantly share code, notes, and snippets.

@georgepradhan
georgepradhan / form-validator.js
Last active December 21, 2015 03:59 — forked from ksolo/form-validator.js
Form Validation
//// start ready function
$(document).ready(function(){
/// start submit function ///
$("#signup").on('submit', function(e){
$("#errors").empty()
var errors = []
var $email = $("input[name=email]").val()
var $password = $("input[name=password]").val()
@georgepradhan
georgepradhan / index.html
Last active December 21, 2015 03:39 — 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>
# Part 1 tests
car = Car.new({:color => 'red'})
p car.drive == :driving # => true
p car.brake == :stopped # => true
p car.instance_variables.sort == [:@color, :@wheels, :@status].sort
p (car.needs_gas? == true || car.needs_gas? == false) #this sometimes yields false, strangely..
p [true, false].include?(car.needs_gas?) #seems to work
car.needs_gas? #seems to always return true or false, so i'm not sure what's going on above..
# Part 1 tests
@georgepradhan
georgepradhan / gist:6025681
Last active December 19, 2015 22:09
numbers in words - 2nd try
NUMBER_WORDS =
{
90 => 'ninety' ,
80 => 'eighty' ,
70 => 'seventy' ,
60 => 'sixty' ,
50 => 'fifty' ,
40 => 'forty' ,
30 => 'thirty' ,
20 => 'twenty' ,
@georgepradhan
georgepradhan / gist:6025666
Created July 18, 2013 00:04
numbers in words - first try
## Pseudo-code ##
# Initialize constant (lookup hash) with digits as keys,
# words as values. e.g. { 1 => one, 2 => two }. This is for 1-9
# Initialize constant (lookup hash) with numbers as keys,
# words as values. e.g. { 10 => ten, 11 => eleven }. This is for 10-19.
# Initialize constant (lookup hash) with 10's place digit as keys,
# prefixes as values. e.g. { 2 => twenty, 3 => thirty }. This is for 20-99.
@georgepradhan
georgepradhan / gist:5877812
Created June 27, 2013 16:13
Recursive method to take an array that potentially contains other arrays and return an array of only individual elements.
@result = []
def flatten(array)
array.each do |element|
if element.respond_to?(:each)
flatten(element)
else
@result.push(element)
end
end
@georgepradhan
georgepradhan / gist:5867679
Created June 26, 2013 14:12
Project Euler #12 - attempt 3 Finally works. Solution takes about 15 seconds so could be optimized further, but not bad.
def tri_num(n)
(n)*(n+1)/2 #formula for the nth triangle number. http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/runsums/triNbProof.html
end
def num_factors(n) #brute force method..
factors = 0
for i in 1..n
factors += 1 if n % i == 0
end
factors
@georgepradhan
georgepradhan / gist:5863403
Created June 25, 2013 23:28
Project Euler #12 - attempt 2
# See my earlier Gist, Project Euler #12 - attempt 1, for context.
puts Time.now
def is_prime?(n)
return true if n == 2
for i in 2..((n**0.5).ceil)
# puts "Checking #{i}... "
if n % i == 0
return false
@georgepradhan
georgepradhan / gist:5863394
Created June 25, 2013 23:26
Project Euler #12 - attempt 1
# The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:
# 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
# Let us list the factors of the first seven triangle numbers:
# 1: 1
# 3: 1,3
# 6: 1,2,3,6
# 10: 1,2,5,10