Skip to content

Instantly share code, notes, and snippets.

@cklanac
cklanac / org-tree-recursion.js
Created April 29, 2017 17:18
Recursion examples
const organization = {name: "Zuckerberg", reports: [
{name: "Schroepfer", reports:[
{name:"Bosworth", reports: [
{name:'Steve'},
{name:'Kyle'},
{name:'Andra', reports: [
{name:'Amy'},
{name:'Chuck'},
{name:'Vinni'}
]}
@cklanac
cklanac / proto-yumlme-builder.js
Created April 29, 2017 17:23
Walking the __proto__chain
;(function(o) {
var o = prompt("Please enter the variable that points to the object.");
if (!window[o]) {
console.log("Sorry, that variable is not found.")
}
var protoChain = ['[' + o + '|' + getProps(window[o]) + ']-__proto__>['+window[o].__proto__.constructor.name+'|'+getProps(window[o].__proto__)+']'];
function buildChain(o) {
if (!o.__proto__) return;
var thisProps = getProps(o.__proto__);
var parentProps = getProps(o.__proto__.__proto__);
@cklanac
cklanac / commands.txt
Last active June 27, 2017 16:56
Show hidden files and delay dock
Show Hidden Files
defaults write com.apple.finder AppleShowAllFiles YES; killall Finder
Hide Hidden files
defaults write com.apple.finder AppleShowAllFiles NO; killall Finder
Delay Dock
defaults write com.apple.dock autohide-delay -int 5; killall Dock
Restore Default Timing
@cklanac
cklanac / preview.css
Last active August 1, 2017 15:39
VSCode Markdown Preview styles - help preview curriculum files
body {
margin: 20px;
max-width: 683px;
padding: 67.5px 20px;
margin: 0 auto;
font-size: 20px;
line-height: 1.5;
}
@cklanac
cklanac / mongoose-buffering.js
Created August 9, 2017 21:53
Experiments with Mongoose Buffering
'use strict';
/**
* Experiments with [Mongoose Buffering](http://mongoosejs.com/docs/connections.html#buffering)
*
* Also handle:
* "DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()`
* instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`.
* See http://mongoosejs.com/docs/connections.html#use-mongo-client"
* v4.10.8 and lower:
@cklanac
cklanac / cat-router.js
Created August 17, 2017 11:40
Test the .catch() condition of an endpoint with a mongoose query
'use strict';
const express = require('express');
const router = express.Router();
const { Cat } = require('./model');
router.get('/', (req, res) => {
Cat.find()
.then(list => {
@cklanac
cklanac / generate.sh
Created August 24, 2017 16:27
shell script to generate the syllabus
# Execute the following using VS Code CodeRunner extentions
# Or simply Copy and paste the relevent sections into bash
# set COHORT environment variable
COHORT=cohort-meta/cohort-2017-06-12.yaml
echo "" > output.md
# node generator/generator.js master-syllabus/00-pre-course-reading.md $COHORT 2 1 >> output.md
: <<'END'
@cklanac
cklanac / primer-dataset-sample.json
Created September 18, 2017 11:44
Mongo primer-dataset-sample.json
{"address":{"building":"326","coord":[-73.989131,40.760039],"street":"West 46 Street","zipcode":"10036"},"borough":"Manhattan","cuisine":"American","grades":[{"date":{"$date":"2014-09-10T00:00:00.000Z"},"grade":"A","score":7},{"date":{"$date":"2013-09-25T00:00:00.000Z"},"grade":"A","score":6},{"date":{"$date":"2012-09-11T00:00:00.000Z"},"grade":"A","score":5},{"date":{"$date":"2012-04-19T00:00:00.000Z"},"grade":"A","score":8},{"date":{"$date":"2011-10-26T00:00:00.000Z"},"grade":"A","score":13}],"name":"Joe Allen Restaurant","restaurant_id":"40365644"}
{"address":{"building":"21","coord":[-73.9990337,40.7143954],"street":"Mott Street","zipcode":"10013"},"borough":"Manhattan","cuisine":"Chinese","grades":[{"date":{"$date":"2014-07-28T00:00:00.000Z"},"grade":"B","score":27},{"date":{"$date":"2013-11-19T00:00:00.000Z"},"grade":"B","score":20},{"date":{"$date":"2013-04-30T00:00:00.000Z"},"grade":"A","score":11},{"date":{"$date":"2012-10-16T00:00:00.000Z"},"grade":"B","score":24},{"date":{"$date":"2012-05-07T00:00:
@cklanac
cklanac / scratch.js
Created November 28, 2017 16:59
Basic Mongoose commands
'use strict';
const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
const { DATABASE_URL } = require('./config');
mongoose.connect(DATABASE_URL, { useMongoClient: true });
const favoriteSchema = mongoose.Schema({
@cklanac
cklanac / reveal-module.md
Last active December 21, 2017 22:59
Reveal Module Pattern

Reveal Module Pattern

A reveal module is an immediately-invoked function expression that returns an object who's methods have closure over the enclosing functions variable scope.

Breaking down the definition, there are 3 key aspects to reveal-module.

  1. The outer function is executed using a the IIFE syntax (...)();. This has the benefit of preventing any polution of the global scope with extra unnecessary varaibles.

  2. The outer function returns an object literal with functions as properties (methods). This is a factory that generates an object with methods (functions) and properties (variables).

  3. Those methods create a closure over the scope so the retain (read, remember) the scope where they were defined. This effectively creates private properties and methods.