Skip to content

Instantly share code, notes, and snippets.

View CrabDude's full-sized avatar

Adam Crabtree CrabDude

View GitHub Profile
@CrabDude
CrabDude / webGuildYarnLab.md
Created March 27, 2017 19:06
Use yarn to create a new project and manage dependencies.

WebGuild: Yarn Lab

The yarn lab incorporates a few steps:

  1. Install yarn
  2. Create a new project with yarn
  3. Installing/reinstall/syncing project dependencies
  4. Add/remove/update some dependencies

Questions? If you have any questions, ping #webguild.

@CrabDude
CrabDude / week1_exercise.md
Created August 12, 2016 21:43
[Sample Exercise] Week 1: Parallel Asynchronous recursiveReaddir

Week 1 Challenge - Parallel Asynchronous recursiveReaddir

This exercise is to build an API for recursively listing the files in a directory in parallel, or in other words, a recursive ls. The purpose of this exercise is to practice control-flow for asynchronous IO, specifically running operations in serial and parallel. Additionally, this exercise will explore the fs filesystem module from core.

IMPORTANT: Review the Control-flow Guide to familiarize yourself with async/await. Ignore Promise and callbacks for now.

Getting Started

The checkpoints below should be implemented as pairs. In pair programming, there are two roles: supervisor and driver.

@CrabDude
CrabDude / callback_contract.md
Last active December 20, 2019 18:50
Node.js Callback Contract

Node.js Callback* Contract

(aka "errback" or "error first callback")

  1. Function that takes 2 arguments
    • first argument is an error
    • second argument is the result
    • Never pass both
    • error should be instanceof Error
  2. Must never excecute on the same tick of the event loop
  3. Must be passed as last argument to function

Week 1 - Command Line Interfaces (CLIs)

This week, we'll ensure our environments are properly setup and walk through the fundamentals of the node.js runtime with a focus on asynchronous programming, control-flow and IO. We'll keep things simple by sticking primarily to the filesystem, stdin and stdout to write basic CLIs like an asynchronous recursive readdir CLI.

Assignment

Assignment 1: Filesystem CLIs due at 10:00pm

This week, we'll build a collection of common filesystem CLIs. The purpose of this project is to develop a basic understanding of control-flow and the node.js runtime, module system and ascyhronous APIs.

@CrabDude
CrabDude / asyncawait.html
Created November 4, 2015 02:03
BayNode Node Night 11/3/15: async/await by Adam Crabtree
<!DOCTYPE html>
<html>
<head>
<title>Async Await</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style type="text/css">
@import url(https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz);
@import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic);
@import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic);
@CrabDude
CrabDude / .eslintrc
Last active November 28, 2017 13:35
.eslintrc with Babel parser support (via babel-eslint package)
{
"env": {
"node": true,
"es6": true
},
"parser": "babel-eslint",
"rules": {
"no-throw-literal": 1,
"strict": "never",
"semi": [2, "never"],
@CrabDude
CrabDude / gist:1597914
Created January 12, 2012 01:33
JS Sandboxing via Harmony Proxies and with()
// in new iframe
var whitelist = {
// add whitelisted globals
};
var handler = {
// Fundamental traps
getOwnPropertyDescriptor: function(name) {
var desc = Object.getOwnPropertyDescriptor(whitelist, name);
@CrabDude
CrabDude / README.md
Created September 30, 2016 09:59
An example of a proper README.md for submission.

Proxy Server

This is a Proxy Server for Node.js submitted as the pre-work requirement for the Node.js Bootcamp.

Time spent: 3h

Completed:

  • Required: Requests to port 8000 are echoed back with the same HTTP headers and body
  • Required: Requests/reponses are proxied to/from the destination server

Creating the Proxy Server

The pre-work incorporates a few steps:

  1. Setup your Node.js environment
  2. Complete the introductory NodeSchool.io Workshoppers
  3. Build a proxy server and setup logging
  4. Develop a command-line interface (CLI) to configure the server
  5. Submit the project for review via Github
  6. Extend your proxy server with additional functions
/*
pins: [{
id, height
}]
*/
// orderedByHeight = [{height: 0, index: 0}]
// Output: datastructure to describe pins
function layoutPins(pins, cols) {
// [{height: 0, index: 0}]