Skip to content

Instantly share code, notes, and snippets.

View JoeKarlsson's full-sized avatar
🏠
Working from home

Joe Karlsson JoeKarlsson

🏠
Working from home
View GitHub Profile
@JoeKarlsson
JoeKarlsson / closure.js
Created September 8, 2016 00:10
Live Coding Closure Examples
var money = 55.50;
var coffeeCost = 8.50;
var drinkCoffee = (function(){
var cupsDrunk = 0;
return function(){
if( money >= coffeeCost ){
money -= coffeeCost;
cupsDrunk++;
}
@JoeKarlsson
JoeKarlsson / User.js
Last active August 16, 2016 21:25
working demo of sequelize and graphql
module.exports = function(sequelize, DataTypes) {
var User = sequelize.define("User", {
username: DataTypes.STRING
});
return User;
};
@JoeKarlsson
JoeKarlsson / 1README.md
Last active January 1, 2023 19:33
graphql + dataloader + express-graphql Live Coding Demo

How to test if Dataloader is working correctly, we are going to turn on server logging in order to see how many queries are being made to our db. If Dataloader is setup correctly, we should only see one hit on our db perrequest, even if duplicate data is being requested. Here's how to enable logging on postgresql. Note - This is the Mac way to enable logging.

  • subl /usr/local/var/postgres/postgresql.conf

  • around line 434 log_statement = 'all' uncomment and set to all log_statement = 'all'

  • then brew service restart postgresql

@JoeKarlsson
JoeKarlsson / README.md
Created July 27, 2016 00:28
Lecture on password encryption, hashing, and bcrypt

How To Safely Store A Password

Use bcrypt. Use bcrypt. Use bcrypt. Use bcrypt. Use bcrypt. Use bcrypt. Use bcrypt. Use bcrypt. Use bcrypt. Use bcrypt.

Why Not {MD5, SHA1, SHA256, SHA512, SHA-3, etc}?

These are all general purpose hash functions, designed to calculate a digest of huge amounts of data in as short a time as possible. This means that they are fantastic for ensuring the integrity of data and utterly rubbish for storing passwords.

bcrypt Solves These Problems

How? Basically, it’s slow as hell. It uses a variant of the Blowfish encryption algorithm’s keying schedule, and introduces a work factor, which allows you to determine how expensive the hash function will be.

@JoeKarlsson
JoeKarlsson / 1proto.js
Last active June 15, 2020 01:22
Prototype Live Coding Examples
var o = {
a: 2,
m: function(b){
return this.a + 1;
}
};
// When calling o.m in this case, 'this' refers to o
console.log(o.m()); // 3
var express = require('express');
var app = express();
// Passport's sole purpose is to authenticate requests, which it does through an extensible set of plugins known as strategies. Passport does not mount routes or assume any particular database schema, which maximizes flexibility and allows application-level decisions to be made by the developer.
var passport = require('passport');
// This module lets you authenticate HTTP requests using the standard basic and digest schemes in your Node.js applications.
var BasicStrategy = require('passport-http').BasicStrategy; // Want to use Basic Authentication Strategy
// Other middleware

Debriefing Classroom Tips

Debrief by questions.

Helps us stay focused on the question and helps see if there are any patterns across cohorts.

Debrief in small groups then medium groups.

We usually debrief in small groups (groups of 4 with whom we observed), and then in combined groups (groups of 8 with 2 groups who saw some of the same classrooms at different times). Smaller networks may have a small-group followed by a whole-group structure.

Share talk time.

We often use a guideline like “everyone speaks once before anyone speaks twice” or “three before me” to help balance air time and hear from everyone.

@JoeKarlsson
JoeKarlsson / README.md
Created February 1, 2016 22:44 — forked from thgaskell/README.md
Basic Authentication with Passport

Basic Authentication with Passport

Basic authentication is one of the simplest authentication strategies because it doesn't require cookies, sessions, or even a login form! Instead, it uses HTTP headers which means credentials are transmitted on each request.

Installation

You will need to install passport and passport-http. The passport-http module is what allows you set up the Basic Authentication Scheme, in addition to a couple other authentication strategies.

$ npm install express passport passport-http --save
@JoeKarlsson
JoeKarlsson / 1-template.md
Last active April 12, 2016 23:13
Mini programming challenge to develop a custom templating engine in Express

##The Challenge The CEO just called and she forgot to develop a new product for the big tradeshow event this year! She needs to present something to appease the hungry shareholders in exactly one hour. Thinking quickly, you realize that a new templating engine would be super cool. It's needs to be done quickly, so it doesn't need to be pretty, but it should have basic functionality. Your challenge is to develop a templating engine for Express from scratch for her to present in under an hour to save the company, impress the shareholders, and achieve enternal glory!

###How it will work: Add functionality to your Express app so that it will be able to render .dlr files (short for DevLeague Rules). When you make a request to the home page, index.dlr will be rendered as HTML.

###The requirements:

  • Use the extenstion .dlr
  • The tempalting engine will replace anything surrounded with double bling '$$'
  • (i.e. $$title$$)

##The Challenge

Write a function that prints a nice Christmas tree of any size to the DOM with it's own star at the top using the shortest code possible. The tree star is an asterisk (*), the tree body is made out of 0 The tree must be at least 10 rows high, and at the bottom of the tree should be a trunk made of 2 pipe characters (|). Every row should be properly indented in the way that the previous row are centered over the next one. Any given row must have 2 more 0s than the previous, except for the first one that is the star and the second, which has only one 0. The result is something like this:

          *
          0
         000
 00000