Skip to content

Instantly share code, notes, and snippets.

@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 / auth.md
Last active December 3, 2018 18:02
Authentication and access control

Passport Local Strategy Auth

In the first lesson, you'll learn all about user management and access control.

We'll use bcryptjs to encrypt user passwords so we don't have to save them as raw text strings.

Note that there are two separate libraries available on NPM bcryptjs (the one we want) and bcrypt (not what we want). Be sure to install bcryptjs, otherwise you may encounter problems on TravisCI.

We'll use Passport to control access to an endpoint at /users/me that only authenticated users can access.

@cklanac
cklanac / cicd-config-clicker.md
Last active June 8, 2023 04:11
CICD: Travis CI and Heroku Instructions: 2 Versions - Point-n-Click and CLI Ninja

Setup Travis and Heroku CICD: Point-n-Click

Continuous Integration with Travis CI

Configure travis.yml

  • Run npm test to ensure tests are working correctly locally
  • Create .travis.yml file in repo
  • Add the following to configure for node
@cklanac
cklanac / capstone-guidelines.md
Last active January 6, 2020 00:55
Capstone Guidelines

API Capstone Guidelines:

Build a RESTful API based on the starter repo. Your API should demonstrate the following features:

  • Resource List: API returns a list of resources.

  • Resource Details: API returns details of a specific resource

  • Resource Update: API allows authenticated users to update a resource. You can choose to update the entire resource or just partial subdata like comments, likes or favorites.

@cklanac
cklanac / defaults-write.sh
Last active September 19, 2022 21:42
Mac Setup Distilled
#!/usr/bin/env bash
# ~/.macos — https://mths.be/macos
# Close any open System Preferences panes, to prevent them from overriding
# settings we’re about to change
osascript -e 'tell application "System Preferences" to quit'
# Ask for the administrator password upfront
sudo -v
@cklanac
cklanac / items.sql
Last active May 9, 2019 18:21
demo database and queries for simple todo shopping list app
DROP TABLE IF EXISTS items_tags;
DROP TABLE IF EXISTS tags;
DROP TABLE IF EXISTS items;
DROP TABLE IF EXISTS users;
CREATE TABLE users (
id serial PRIMARY KEY,
email text NOT NULL,
username text NOT NULL
@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 / npm-scripts-setup.md
Created December 18, 2017 13:21
NPM script commands at various phases of the course

npm-run-setups

The primary question is whether npm start and npm test should be setup for developer convenience and other commands like npm run heroku and npm run travis should be setup for services. Or should npm start and npm test should be kept for production and test environments respectively and customer scripts like npm run dev:start and npm run dev:test should be created for development.

The secondary question is... what should they be named?

Below are examples of the scripts at the various phases of the course

Basic - Node/Express