Skip to content

Instantly share code, notes, and snippets.

@peyo
peyo / gist:e613def0c110e0288413e6e3db6469de
Last active December 8, 2019 23:33
Analogy of client and server
----- ANALOGY OF CLIENT AND SERVER -----
A simple analogy of client and server might be an interaction between a student and a teacher.
A student, Becky, is preparing a presentation on blue whales but does not have all the information she needs to create a detailed, clear, and visual presentation. Becky and her presentation is a client in this case. Luckily, Becky has a trusty teacher, Mr. Shure, she can visit to ask questions. Her teacher in this case is a server.
Becky asks her Mr. Shure for facts, where she can find books, and visuals on blue whales. Becky asking her teacher for information is a request. Her teacher responds by providing her with a sheet of paper that contains a written list of blue whale facts, titles and authors of books on these amazing creatures, and search queries for sites with images of blue whales swimming in the world's oceans. This written list a response.
With the list of facts, books, and search queries for images, Becky is able to compile a beautiful presenation. This pres
// HEADLINE
Hello, I'm Peter. I'm a full-stack developer, UX enthusiast, and avid learner.
// BIO
I'm a recent graduate of the Engineering Flex boot camp at Thinkful. I believe that curiosity and openness are at the root of self-discipline and diligence. These traits are the catalysts that afford us the ability to tackle problems. Coding to me is a skill set that will allow for simple to complex solutions.
When I'm not coding, I'm often found traveling to new cities, visiting museums and gardens, relaxing on a lounge chair reading, or making candles. My current learning projects include starting a small business and writing my first book.
Google Drive link
https://drive.google.com/drive/folders/1z8iz6w-sG9RgF5wUSVjC6UDqkL-PVdhi?usp=sharing
@peyo
peyo / gist:423e5782c40b2839de3049d8cf5fc50e
Last active November 5, 2019 17:18
Explanation of an algorithm - most frequent word
function getTokens(rawString) {
// NB: `.filter(Boolean)` removes any falsy items from an array
return rawString.toLowerCase().split(/[ ,!.";:-]+/).filter(Boolean).sort();
}
// create a function called 'mostFrequentWord' with argument 'text'.
function mostFrequentWord(text) {
// declare the variable 'words' to 'getTokens(text)'.
let words = getTokens(text);
// declare the variable 'wordFrequencies' as an object.
https://repl.it/@PeterYoon/Deleting-keys-drill
/* how come we can't use console.log instead of return? */
https://repl.it/@PeterYoon/Self-reference-drill
/* i originally wrote 'return updateObject()'. Realized that in the instructions it asked to return it. It stands for obj. */
https://repl.it/@PeterYoon/Object-updater-drill
/* the toughest part is knowning when the use a comma or a semi colon */
https://repl.it/@PeterYoon/Object-creator-drill
@peyo
peyo / gist:e72becc18e4b1e3c6077599638b1d10c
Created October 28, 2019 23:08
discussing variable scope
Q: What is scope? Your explanation should include the idea of global vs. block scope.
A: Scope defines which part of the code can access a particular variable. A variable in a global scope is available everywhere. Any variable that is declared outside of a function has a global scope. A variable in a block scope is limited to a set of instructions within a function. This appears to be what a local scope is.
Q: Why are global variables avoided?
A: (1) Debugging Issues: Global variables are avoided because it can cause issues down the line where debugging can be difficult. Every function has access to them and as the code base becomes large it becomes increasingly difficult to figure our which functions read and write these variables. (2) Difficult Collaboration: It makes it harder to pass around different functions as it would take a lot of time to understand which functions interact with the global variable.
Q: Explain JavaScript's strict mode
A: Strict mode disallows for global variables, essentially catch
@peyo
peyo / gist:eaf5dff23ce17a34a01715e573584600
Last active October 28, 2019 20:05
replacing specific items in array with another item using for loop and multiple if / else if / else statements
/* repl: https://repl.it/@PeterYoon/fizzbuzz-drill-js
function fizzBuzz(countTo) {
let fbList = [];
for (let i = 1; i <= countTo; i++) {
if (i % 3 === 0 && i % 5 === 0) {
fbList.push('fizzbuzz');
} else if (i % 3 === 0) {
fbList.push('fizz');