Last active
May 12, 2017 04:14
-
-
Save danielnmai/fa48ede9cb85810ce890dfa495c24a59 to your computer and use it in GitHub Desktop.
Today I Learned - Week 2 Bootcamp
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
#Copyright Daniel Mai 04/30/2017 | |
#Advanced Ruby coding: | |
#Write me a function to generate/print/store the first “n” prime numbers. | |
#The algorithm to find prime numbers in inspired by the pseudocode provided in | |
#https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes | |
#The sieve of Eratosthenes is quite efficient to quickly look up prime numbers | |
#in a list of n numbers | |
#Accept an input of up to 30 numbers | |
n = 30 | |
#Create an array of Boolean values | |
#The array needs to have n-1 elements because the index at n would be n + 1 | |
ary = Array.new(n - 1).map{ |value| value = true} | |
#0 and 1 are not prime numbers, so we don't need values | |
#at index 0 and index 1 in the array | |
ary.unshift(nil) | |
ary.unshift(nil) | |
#start the first iterator from 2 | |
i = 2 | |
#initialize an inner iterator | |
j = 0 | |
#The idea is to eliminate all multiplications of i by setting their values to false | |
#For example, any multiplication of 2 is 4,6,8,10. Those are not prime numbers. | |
#Loop until i reaches the square root of input | |
while i <= Math.sqrt(n) | |
#check if a number has any multiplication of itself | |
if ary[i] | |
#reset j iterator and initialize k | |
k = 2 | |
j = 2 | |
#Perform the prime check | |
while j <= n | |
#Set all multiplications of i to boolean value FALSE | |
j = i * k | |
#the if condition is to make sure j will not go higher than n | |
ary[j] = false if j <= n | |
#increment k | |
k += 1 | |
end | |
end | |
#increment i | |
i += 1 | |
end | |
#Create an empty array to hold prime numbers | |
prime_numbers = [] | |
#Loop through the array again | |
#Any value that is true, its index is a prime | |
ary.each_index do |value| | |
if ary[value] | |
prime_numbers << value | |
end | |
end | |
#Output the result | |
p prime_numbers | |
#[2, 3, 5, 7, 11, 13, 17, 19, 23, 29] | |
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
------ Day 1 ------- | |
create database on Rails: | |
rails db:create | |
rails generate model Recipe title:string chef:string ingredients:string directions:string image:string prep_time:integer | |
CRUD: | |
Read: | |
ModelName.all ==> return an array of hashes of all items in the database | |
ModelName.first / ModelName.last ==> return a hash of an item in the database | |
ModelName.where(attribute:"Name") => return all items that match the attribute | |
item.update(attribute:"New value") ==> update the item in the database | |
item.attribute = "new value" | |
item.save ==> save the change to the database | |
ModelName.create(attribute:"value") ==> create an item in the database | |
------ Day 2 ------- | |
-------5/2/17---------- | |
SASS: better than CSS? | |
SASS has things that CSS don't have: | |
- Variable | |
- Nesting | |
------ Day 3 ------- | |
Three parts of an HTML request: | |
the verb (i.e GET) | |
the URL | |
the attribute | |
URL Parameters: Use wildcard (mywebsite.com/:wildcard) and query (mywebsite.com?querry=keyword) to navigate the website. | |
We can also use Form to submit information to the server | |
------ Day 4 ------- | |
When using form to submit information, instead of just putting text next to the input textbox, wrap it in a <label> tag, for better web accessibility (for blinded people, the web browser will read what's inside the label tag, making them easier to understand the form). | |
------ Day 5 ------- | |
People get hired just by blogging. | |
What to look for in a junior developer: | |
Enthusiam | |
Attention to detail | |
Hunger for learning | |
Thirst to contribute | |
What have you built? | |
How do you get unstuck? | |
Command+Shift+3: Take screen shot of whole screen | |
Command+Shift+4: Take screenshot of portion of the screen that you specify | |
When whiteboarding, always start with: | |
- The input | |
- Expected output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment