Skip to content

Instantly share code, notes, and snippets.

View CrabDude's full-sized avatar

Adam Crabtree CrabDude

View GitHub Profile
@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 / 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 / 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 / 1_overview.md
Created April 10, 2015 19:25
Proxy Echo Server Overview

Testing

async()=>{
// Pointless calling await because crypto.pbkdf2 returns nothing
await crypto.pbkdf2('asdf', 'salt', 4096, 512, 'sha256', function(err, key) {
if (err) throw err
user.password = key.toString('hex')
console.log(user.password)
// return key.toString('hex') // 'c5e478d...1469e50'
})
@CrabDude
CrabDude / README.md
Last active August 29, 2015 14:27
A sample Node.js Bootcamp submission README

Proxy Server

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

Time spent: [Write the number of hours you spend here]

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
// NOT AN APPLICATION, I JUST WANTED TO TAKE YOUR TEST. =)
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}
// ANSWER
@CrabDude
CrabDude / inheritance.js
Created February 8, 2011 21:32
Private.js Example: Inheritable Private Instance Members
// Class.extend takes a function that returns the options object
// it is passed the accessor function generated in the Pvt.js example above
var Person = Class.extend(function(pvt) {
// private static member
var species = "Homo sapien";
return {
init: function(isDancing) {
// pvt(this).invisible === undefined
@CrabDude
CrabDude / basic.js
Created February 10, 2011 20:32
Pvt.js Example: Simple (Non-Inheritable) Private Instance Members
// Utilize a closure to keep the private members private
var Person = (function() {
// Generate a private instance member accessor function "pvt"
var pvt = Pvt(),
// private static member
species = "Homo sapien";
var Self = function(isDancing) {
@CrabDude
CrabDude / crockford.js
Created February 10, 2011 21:40
Crockford's "Private Members in JavaScript"
// Public
function Constructor(...) {
this.membername = value;
}
Constructor.prototype.membername = value;
// Private
function Constructor(...) {
var that = this;
var membername = value;