Skip to content

Instantly share code, notes, and snippets.

View mikedao's full-sized avatar
🤷

Michael Dao mikedao

🤷
View GitHub Profile
@mikedao
mikedao / credit_check.rb
Created December 17, 2014 06:02
Luhn's Algorithm
def validator(card)
card.chars
.map { |n| n.to_i }
.map.with_index { |n, index| index.even? ? n * 2 : n }
.map { |n| n.to_s.length == 2 ? n.to_s[0].to_i + n.to_s[1].to_i : n }
.reduce(:+) % 10 == 0 ? "Valid" : "Invalid"
end
Create VPC
Create Security Group
Create incoming and outgoing rules for SSH, HTTP, Sinatra and Rackup, 443
Create Key Pair
cd ~/.ssh
mv ~/Downloads/Turing.pem .
chmod 400 Turing.pem
ssh-add -k Turing.pem
Launch Instance
ubuntu 14.04
class Centaur
attr_reader :name,
:breed
def initialize(name, breed)
@name = name
@breed = breed
@actions = 0
@standing = true
end
@mikedao
mikedao / gist:75a8661d793dab413611
Created December 31, 2014 16:11
TrafficSpy Psedocode
1. Check to see if application is registered
2. Check to see if payload is present
3. Check to see if request is a duplicate one.
4. Sanitize payload
5. Insert payload into database.
@mikedao
mikedao / OSes
Last active August 29, 2015 14:12
Get all requests that match :identifier
get matching user_agent_ids
get matching user_agent
os = user_agent.split(' ')[1]
count requests that match os
create hash {os => count }
display os[1..-2] + count
@mikedao
mikedao / gist:ff1ceceb253d89c65574
Created January 6, 2015 19:46
Public Key Cryptography Outline
Public Key Cryptography
The Problem: How do we communicate securely on the internet?
- We have to encrypt our communications.
- How do two parties who have never met, agree on a key when all of their communications are public?
- The answer: Diffie Hellman Key Exchange. -Whitfield Diffie, Martin Hellman
- The first implementation of public key cryptography as envisioned by Ralph Merkle.
The Setup:
- Alice wants to Talk to Bob.

Description

During online gaming (or any video game that requires teamwork) , there is often times that you need to speak to your teammates. Given the nature of the game, it may be inconvenient to say full sentences and it's for this reason that a lot of games have acronyms in place of sentences that are regularly said.

Example

gg : expands to 'Good Game' brb : expands to 'be right back' and so on... This is even evident on IRC's and other chat systems. However, all this abbreviated text can be confusing and intimidating for someone new to a game. They're not going to instantly know what 'gl hf all'(good luck have fun all) means. It is with this problem that you come in.

@mikedao
mikedao / gist:a5e07551907172086eb7
Last active August 29, 2015 14:13
ISBN Validator

Description

ISBN's (International Standard Book Numbers) are identifiers for books. Given the correct sequence of digits, one book can be identified out of millions of others thanks to this ISBN. But when is an ISBN not just a random slurry of digits? That's for you to find out.

Rules

Given the following constraints of the ISBN number, you should write a function that can return True if a number is a valid ISBN and False otherwise. An ISBN is a ten digit code which identifies a book. The first nine digits represent the book and the last digit is used to make sure the ISBN is correct. To verify an ISBN you :- obtain the sum of 10 times the first digit, 9 times the second digit, 8 times the third digit... all the way till you add 1 times the last digit. If the sum leaves no remainder when divided by 11 the code is a valid ISBN. For example : 0-7475-3269-9 is Valid because

class Phoenix
attr_reader :name, :age, :lives, :revives
def initialize(name, age=0)
@name = name
@age = age
@alive = true
@lives = 0
@revives = 0
end
@mikedao
mikedao / Ben.md
Created January 22, 2015 21:57
Advice from Ben

Don't load db.seeds in test runs

Add factory_girl (read the GETTING_STARTED.md file, at least the first half)

Build the data that each test needs in that test.

Use the 4-phase test plan: setup, exercise, verify, teardown

You can use two numbers in code: 1 and 0. The rest are constants.