Skip to content

Instantly share code, notes, and snippets.

View alec-huang-labs's full-sized avatar
⬅️
Me & Teddy !

alec huang alec-huang-labs

⬅️
Me & Teddy !
View GitHub Profile

When first confronted with node.js, you are not only presented with a completely new programming environment. You also encounter what is often referred to as callback hell accompanied by weird unfamiliar programming patterns. One of these is the way node treats callback functions.

The following post explains the conventions that node.js uses for its callback patterns (referred to as Continuation-passing style) and how you should implement them in order to comply.

First argument is an error object pattern

Node expects - almost - all callback functions to accept an Error object as the first argument. If no error occurred, the first argument should be null. If you use inline anonymous functions, this is a typical code snippet that you will encounter using node:

// include the filesystem module
var fs = require('fs');
We can't make this file beautiful and searchable because it's too large.
BOROUGH,NEIGHBORHOOD,BUILDING CLASS CATEGORY,TAX CLASS AT PRESENT,BLOCK,LOT,EASE-MENT,BUILDING CLASS AT PRESENT,ADDRESS,APARTMENT NUMBER,ZIP CODE,RESIDENTIAL UNITS,COMMERCIAL UNITS,TOTAL UNITS,LAND SQUARE FEET,GROSS SQUARE FEET,YEAR BUILT,TAX CLASS AT TIME OF SALE,BUILDING CLASS AT TIME OF SALE, SALE PRICE ,SALE DATE
1,ALPHABET CITY,02 TWO FAMILY DWELLINGS,1,377,72,,B9,231 EAST 7TH,,10009,2,0,2,"1,718","5,154",1901,1,B9,0,10/2/2020
1,ALPHABET CITY,03 THREE FAMILY DWELLINGS,1,377,66,,C0,243 EAST 7TH STREET,,10009,3,0,3,"2,381","3,084",1899,1,C0,0,10/31/2020
1,ALPHABET CITY,03 THREE FAMILY DWELLINGS,1,377,66,,C0,243 EAST 7TH STREET,,10009,3,0,3,"2,381","3,084",1899,1,C0,"4,350,000",7/16/2020
1,ALPHABET CITY,07 RENTALS - WALKUP APARTMENTS,2A,376,23,,C3,"262 EAST 7TH STREET, 4",,10009,4,0,4,"2,059","4,154",1900,2,C3,"600,000",12/12/2019
1,ALPHABET CITY,07 RENTALS - WALKUP APARTMENTS,2,376,28,,C4,272 EAST 7TH STREET,,10009,24,0,24,"2,764","13,206",1900,2,C4,1,6/26/2020
1,ALPHABET CITY,07 RENTALS - WALKUP APARTMENT
We can't make this file beautiful and searchable because it's too large.
BOROUGH,NEIGHBORHOOD,BUILDING CLASS CATEGORY,TAX CLASS AT PRESENT,BLOCK,LOT,EASE-MENT,BUILDING CLASS AT PRESENT,ADDRESS,APARTMENT NUMBER,ZIP CODE,RESIDENTIAL UNITS,COMMERCIAL UNITS,TOTAL UNITS,LAND SQUARE FEET,GROSS SQUARE FEET,YEAR BUILT,TAX CLASS AT TIME OF SALE,BUILDING CLASS AT TIME OF SALE, SALE PRICE ,SALE DATE
1,ALPHABET CITY,03 THREE FAMILY DWELLINGS,1,377,66,,C0,243 EAST 7TH STREET,,10009,3,0,3,"2,381","3,084",1899,1,C0,"4,350,000",7/16/2020
1,ALPHABET CITY,03 THREE FAMILY DWELLINGS,1,393,9,,C0,604 EAST 11TH STREET,,10009,3,0,3,"2,375","5,110",1939,1,C0,0,10/24/2019
1,ALPHABET CITY,07 RENTALS - WALKUP APARTMENTS,2A,376,23,,C3,"262 EAST 7TH STREET, 4",,10009,4,0,4,"2,059","4,154",1900,2,C3,"600,000",12/12/2019
1,ALPHABET CITY,07 RENTALS - WALKUP APARTMENTS,2A,376,26,,C3,268 EAST 7TH STREET,,10009,4,0,4,"2,065","3,491",1900,2,C3,"4,350,000",10/31/2019
1,ALPHABET CITY,07 RENTALS - WALKUP APARTMENTS,2,376,28,,C4,272 EAST 7TH STREET,,10009,24,0,24,"2,764","13,206",1900,2,C4,1,6/26/2020
1,ALPHABET CITY,07
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alec-huang-labs
alec-huang-labs / CashRegister.js
Created September 12, 2020 00:45
Cash Register
function checkCashRegister(price, cash, cid) {
let originalDrawer = cid.map(arr => [...arr]);
let drawerTotal = cid.reduce((accum, obj) => accum + obj[1], 0);
let names = ["ONE HUNDRED", "TWENTY", "TEN", "FIVE", "ONE", "QUARTER", "DIME", "NICKEL", "PENNY"];
let values = [100, 20, 10, 5, 1, 0.25, 0.10, 0.05, 0.01];
var changeObj = {
status: "",
change: []
}