Skip to content

Instantly share code, notes, and snippets.

View nbeers22's full-sized avatar

Nathan Beers nbeers22

  • Jacksonville Beach, FL
View GitHub Profile
@nbeers22
nbeers22 / scripts.md
Last active April 3, 2019 08:26
shopping list pseudocode

Adding New Items

  1. When form is submitted, prevent form from refreshing and get value of input
  2. Add the new item to the STORE variable

Delete Item from list

  1. use click handler to determine which item was clicked using $(this)
  2. traverse up the DOM to the parent
  3. Grab the id in data-item-id to use to remove from the STORE
  4. use jQuery .remove() to remove the
  5. from the DOM completely
@nbeers22
nbeers22 / scope.md
Created April 1, 2019 08:36
JavaScript Variable Scope

Questions: What is scope? Your explanation should include the idea of global vs. block scope. Why are global variables avoided? Explain JavaScript's strict mode What are side effects, and what is a pure function?

  1. Scope determines the visibility/accessibility of variables, objects, and funcitons within the code. JavaScript has global scope, function scope, and with the addition of ES6, block scope using let and const. Global variables are available everywhere but are typically viewed as bad practice because they can produce unintended results down the line. They also can be a performance hit, because when JavaScript is compiled it checks for variable
@nbeers22
nbeers22 / scripts.js
Created March 31, 2019 11:44
Thinful JavaScript number functions
// Create a function called computeArea that takes two arguments: width and height.
// It returns the area of a rectangle whose width is width and height is height.
// So computeArea(2, 2) would return 4, and computeArea(3, 5) would return 15.
const computeArea = (width, height) => width * height;
// Create 2 functions, one called celsToFahr that converts Celsius to Fahrenheit and
// another called fahrToCels that converts Fahrenheit to Celsius. celsToFahr takes one
// argument, celsTemp, and fahrToCels takes one argument, fahrTemp.
// [°F] = [°C] × ​9⁄5 + 32
// [°C] = ([°F] − 32) × ​5⁄9
@nbeers22
nbeers22 / thinkful.js
Last active March 31, 2019 11:05
Thinkful Functions
// Create a function called wisePerson that takes 2 arguments: wiseType and whatToSay.
// This function takes a block of text and presents it as a quote from the wise person.
// wiseType is the person the quote will be attributed to, and whatToSay is what the wise person will be quoted as saying.
// When called like this: wisePerson('goat', 'Hello world') should return the string 'A wise goat once said: "Hello world".'
const wisePerson = (wiseType, whatToSay) => `A wise ${wiseType} once said: "${whatToSay}"`
// Create a function that takes a single argument: whatToShout.
@nbeers22
nbeers22 / remove-post-type-from-url.php
Last active October 19, 2016 18:46
WordPress - Remove the custom post type name from the URL
<?php
// Remove custom post type name from URL for special posts
function remove_cpt_slug( $post_link, $post, $leavename ) {
if ( 'special' != $post->post_type || 'publish' != $post->post_status ) {
return $post_link;
}
$post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );