- Download this application skeleton.
- Convert the app to use AJAX.
- Add any files you changed to your gist and submit your code.
This file contains hidden or 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
| //// 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() |
This file contains hidden or 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 hidden or 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
| # 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 |
This file contains hidden or 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
| NUMBER_WORDS = | |
| { | |
| 90 => 'ninety' , | |
| 80 => 'eighty' , | |
| 70 => 'seventy' , | |
| 60 => 'sixty' , | |
| 50 => 'fifty' , | |
| 40 => 'forty' , | |
| 30 => 'thirty' , | |
| 20 => 'twenty' , |
This file contains hidden or 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
| ## 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. |
This file contains hidden or 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
| @result = [] | |
| def flatten(array) | |
| array.each do |element| | |
| if element.respond_to?(:each) | |
| flatten(element) | |
| else | |
| @result.push(element) | |
| end | |
| end |
This file contains hidden or 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 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 |
This file contains hidden or 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
| # 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 |
This file contains hidden or 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
| # 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 |
NewerOlder