Skip to content

Instantly share code, notes, and snippets.

View awhit012's full-sized avatar

Alex White awhit012

View GitHub Profile

Proposal for Curriculum: Node + Express

This is a proposal for the creation of a text-based curriculum, using Markdown. Each lesson would include learning objectives, small code examples, and links to external resources. This proposal does not include full functioning "solution code", only code samples to demonstrate each concept.

This curriculum covers Node and Express as a JSON API, not as a full web application platform using something like Pug. It is a partner course to the React material, intended to enable users to use this backend to talk to a decoupled front end. The two courses together are not meant to be comprehensive. This does not cover, for example, how to enable CORS.

Unit I: Intro to Node

Map

Objectives

  • Use .map() to mutate an array of objects
  • Articulate when it should be used over a 'for' or 'forEach' loop

Why?

In JavaScript we can always use for loops to iterate over arrays. However, arrays have many functions that can be performed on them that are more lexically clear. The .map function is designed for when we want to mutate items in an array and return a new, mutated array.

const alphabet = {
"a": 0,
"b": 1,
"c": 2,
"d": 3,
"e": 4,
"f": 5,
"g": 6,
"h": 7,
"i": 8,
# GET
curl -v http://localhost:8080/code-snippets
# POST
curl -d '{"name": "my code snippet", "snippet": "( ()=> { return `HELLOOOOOOOOO!!!!!!`})()"}' -H 'Content-Type: application/json'   http://localhost:8080/code-snippets
# PUT
const http = require('http')
const books = [
{id: 1, title: "You Don't Know JS", author: "Kyle Simpson"},
{id: 2, title: "Sometimes a Great Notion", author: "Ken Kesey"},
{id: 3, title: "The Teachings of Don Juan", author: "Carlos Casteneda"}
]
// check the url, if it is /books or /books/:id
// check the method, if it is GET, POST, PUT, or DELETE
// depending on the above, we want to send back our response.
class StopWatch {
constructor() {
this.seconds = 0
this.timerId = null
this.startButton = document.getElementById("start")
this.pauseButton = document.getElementById("pause")
this.resetButton = document.getElementById("reset")
this.h1 = document.getElementsByTagName("h1")[0]
this.addEventListeners()
}
@awhit012
awhit012 / heroku-deploy.md
Created June 9, 2016 18:57
Heroku Deploy

Heroku Deploy

  1. Have a Sinatra app that works on localhost that is committed, up to date and on the master branch.
  2. heroku login and enter credentials
  3. heroku create *YOUR_APP_NAME*
  4. git push heroku master
  5. heroku run rake db:create
  6. heroku run rake db:migrate
  7. heroku run rake db:seed
  8. heroku open
# This is a script to delete every comment and post on a reddit account.
# You may have to run it several times, depending on how many comments and posts you have on your user, due to
# the batching process of reddit's API.
import praw, csv, pprint
USERNAME = ""
PASSWORD = ""
class Bot:
// class notes: https://github.com/DelmerGA/intermediate_talk
// javascript in one pic: https://github.com/coodict/javascript-in-one-pic
// Our code to do something a random number of seconds later
var fullName = function(args){
return args.firstName + " " + args.lastName;
};
var joke = function(args){
@awhit012
awhit012 / quick_refactor.js
Created December 22, 2015 00:12
a quick refactor of a students code
function Game(){
this.prophesy = document.getElementById("prophesy");
this.current_user;
}
Game.prototype.smash() {
var cookie = document.getElementById("cookie");
if (cookie.style.display === '') {
cookie.style.display = 'none';