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 / 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$$)
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
@JoeKarlsson
JoeKarlsson / recursion.js
Last active June 23, 2016 19:14
Live Coding on recursion examples.
var recursify = function(num){
//base case
if(num === 0){
return;
}
console.log(num);
recursify(--num);
};
recursify(10); // 10 9 8 7 6 5 4 3 2 1
@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 / 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 / posthoisting.js
Created September 8, 2016 18:55
Hoisting live coding demo
function tres(){
var foo = 4
return 3;
}
var uno;
var dos;
const quatro;
@JoeKarlsson
JoeKarlsson / Missile.js
Last active September 14, 2016 02:23
ES6 OOP Example
'use strict'
const Rocket = require('./Rocket.js');
module.exports = class Missle extends Rocket {
constructor( speed, year ) {
super('Mach 10', 'North Korea', year)
this._speed = speed;
}
@JoeKarlsson
JoeKarlsson / server.js
Created October 6, 2016 19:19
Live Coding Demo for the HTTP Node Module
'use strict'
const http = require('http');
const PORT = 3000;
http.createServer(( request, response ) => {
console.log('request: ', request.url);
console.log('request: ', request.method);
@JoeKarlsson
JoeKarlsson / immutable_demo.js
Last active October 29, 2016 20:20
Immutable JS demo
const Immutable = require('immutable');
const data = Immutable.Map({
people: Immutable.List(['Joe', 'Ray', 'Nigel']),
test: 'Hello World'
})
const data2 = data.updateIn(['people'], ((people) => {
return people.set(0, 'Russel');
}));
### Keybase proof
I hereby claim:
* I am joekarlsson on github.
* I am joekarlsson (https://keybase.io/joekarlsson) on keybase.
* I have a public key whose fingerprint is E626 4B25 7B52 A96C 71D3 8B69 E050 65C4 A621 9367
To claim this, I am signing this object: