Skip to content

Instantly share code, notes, and snippets.

@cklanac
cklanac / Javascript OO Cheat Sheet
Last active September 14, 2022 09:35
Javascript OO Cheat Sheet
/***********************************************************************************************************************
***********************************************************************************************************************
* CONTENTS:
* Native Object
* Object Literal
* Basic Object
* Psuedo-Class
* Self Executing/Invoking Structure
* Lazy Function
* Module Pattern
@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.

@cklanac
cklanac / shopping-list-api.md
Created November 16, 2016 22:25
Creating a Shopping List API

Creating a Shopping List API

In this lesson you will be using your Node.js and Express skills to create the back end for a simple Shopping List application. The application will allow users to add, read, update and remove shopping items. You'll learn about the CRUD model and RESTful APIs, then put this into practice when creating the back end.

Goals

  • Understand the basics of CRUD and REST
  • Create RESTful endpoints which perform all of the CRUD operations

Intro to REST and CRUD

@cklanac
cklanac / server.js
Created April 22, 2017 18:07
Promisify Run Server, Close Server
// closeServer needs access to a server object, but that only
// gets created when `runServer` runs, so we declare `server` here
// and then assign a value to it in run
let server = http.createServer(app)
.on('listening', () => {
console.info(`Your app is listening on port ${server.address().port}`);
})
.on('close', () => {
console.info('server closed');
})
@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 / logger.js
Created August 15, 2017 20:53
Morgan, Winston and Loggly
'use strict';
const { LOGGLY_TOKEN } = require('../config');
/**
* [Winston](https://github.com/winstonjs/winston)
* A multi-tranport async logging library
*
* Use winston to implement our logger, but the rest of the app uses
* the generic logger interface that we export. This decouples logging
* logic in our code from implementation with Winston.