Skip to content

Instantly share code, notes, and snippets.

##videos:

This is a rather short video to get started with C++. After the video, you should be able to start impl some algorithms and data structures like in single files.

The course is based on the excellent textbook Accelerated C++ by Andrew Koenig and Barbara E. Moo., taught by Jeremy Siek, a professor at the University of Colorado. No prior knowledge of C++ is assumed.

Part 1 covers the first seven chapters of Accelerated C++, in particular, Chapters 0 through. Like the textbook, the course quickly dives into problem solving and making use of the C++ standard library, including strings, vectors, and lists.

@badmonster0
badmonster0 / heap
Last active December 10, 2015 04:49
Simple Heap Impl. Support add, pop and print. Support Max heap and min heap
var Heap = function(type){
this.heap = []
this.type = type || "MAX";
}
Heap.prototype.print = function(){
var r;
if (this.type == "MIN"){
r = []
for (var i = 0; i< this.heap.length; i++){
r.push(-this.heap[i])
@badmonster0
badmonster0 / gist:f15f8c493f87ce41dd04
Last active August 29, 2015 14:20
where is the best place to extend cookie expire using passport?
// process the login form
app.post('/login', passport.authenticate('local-login', {
// successRedirect: '/profile',
// failureRedirect: '/',
// failureFlash: true
}), getLoginInfo)
//Instead of redirecting after passport, we want to run another middleware, then proceeds to redirect
function getLoginInfo(req, res, next){
req.session.cookie.maxAge = 14 * 24 * 3600
@badmonster0
badmonster0 / gist:d071027fad39507b9c9f
Created May 8, 2015 05:41
Install the Babel ESNext Transpiler

The new JavaScript language features in ESNext will eventually make it into V8, on which node.js and io.js run. Rather than wait for V8 to support ESNext, we'll use Babel to transpile ESNext code into a JavaScript version currently supported by node.js and io.js.

npm install -g babel                                 # Install Babel
# Alias babel-node to bode with strict and experimental turned on
bodealias="alias bode='babel-node --optional strict --stage 1 -- '"
echo $bodealias >> ~/.bash_profile                   # Persist alias
bode                                                 # Use ESNext today
>
@badmonster0
badmonster0 / gist:71638f362b4405551336
Created May 8, 2015 05:32
await User.findById(id).exec()
//mongo built in promise
let user = await User.findById(id).exec()
//prefered, consitent with the pattern that how we use await/promise/nodeify
let user = await User.promise.findById(id)
//they have the same result, they return the same promise.
@badmonster0
badmonster0 / gist:9293b234ea92d63b73d8
Created May 8, 2015 05:23
How to create a simple passport strategy using es7 + babel + express
let app = express()
app.use(passport.initialize())

let userConst = {
        email: '[email protected]',
        password: bcrypt.hashSync('asdf', SALT)
}
    
@badmonster0
badmonster0 / gist:3ba92e73ff5d21d696b9
Last active August 29, 2015 14:20
nodeify spread:true explaination

run bode

let promise = Promise.resolve([false, 'error message'])
let nodeify = require('bluebird-nodeify')
nodeify(promise, console.log) 
# output null [ false, 'error message' ]
nodeify(promise, console.log, {spread:true});
#output null false 'error message'