Skip to content

Instantly share code, notes, and snippets.

View CrabDude's full-sized avatar

Adam Crabtree CrabDude

View GitHub Profile
@CrabDude
CrabDude / README.md
Last active August 29, 2015 14:18
Dropbox README

Dropbox (raw)

This is a basic Dropbox clone to sync files across multiple remote folders.

Time spent: <Number of hours spent>

Features

Required

@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:f53f8996fb8816bb6372
Last active August 29, 2015 14:10
Node.js with FB Flow
// @flow weak
/* jshint ignore:start */
declare module 'http' {
declare function createServer(callback: (req: httpIncomingMessage, res: httpServerResponse) => void): httpServer
}
// declare class http {
// createServer(callback: (req: httpIncomingMessage, res: httpServerResponse) => void): httpServer
// }
@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
@CrabDude
CrabDude / asyncgen_listfiles.js
Created March 27, 2014 21:23
ListDir: Async Generator all the things!
// List all files recursively within a directory with maximum parallelism
"use strict";
let path = require('path')
let fs = require('fs')
let co = require('co')
let _ = require('lodash')
Function.prototype.partial = function() {
var args = Array.prototype.slice.call(arguments)
args.unshift(null)
@CrabDude
CrabDude / desc.txt
Last active January 3, 2016 12:48
South Bay Node.js Enterprise Breakfast
What: Breakfast for south bay enterprise node.js leaders
When: 8-9:30am, Friday, January 24
Where:
LinkedIn
2029 Stierlin Ct
Mountain View, CA 94043
Why: To regularly meet to discuss enterprise node.js concerns and encourage increased community in the south bay.
function bar() {
return function(cb) {
throw new Error('asdf')
setImmediate(function() {
cb()
})
}
}
function* foo() {
function* foo() {
// Parallel calls with no helper lib
var paths = ['A.js', 'B.js']
var group = []
for (path in paths) {
group.push(fs.readFile(path))
}
var files = yield group
// Serial calls
var fs = require('fs')
var $$ = require('$$')
$$(function*($) {
var fileNames = ['A.txt', 'B.txt', 'C.txt', 'D.txt']
for (fileName in fileNames) {
$(fs.readFile(fileName))
}
var fileDataArray = yield
})
@CrabDude
CrabDude / Example1.js
Created May 21, 2012 06:19
Functional Programming with Streams in node.js
// Load the http module
var http = require('http');
// Setup a HTTP server, listen on port 8080
http.createServer(function (req, res) {
res.writeHead(200, {
'Content-Type': 'text/plain'
});
res.end('Hello World');
}).listen(8080, '127.0.0.1');