This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def permute(arr) | |
permutation(arr.sort) | |
end | |
def permutation(arr, result=[]) | |
k = nil | |
result += [arr.dup] | |
(arr.length-1).times do |i| | |
if arr[i] < arr[i+1] | |
k = i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function permute(arr){ | |
return permutation(arr.sort()); | |
} | |
function permutation(arr, result){ | |
result = typeof result !== 'undefined' ? result : []; | |
result = result.concat([arr]); | |
//find index k | |
var k = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////////////////////////// | |
//// B-TREE OF ORDER 3 //// | |
/////////////////////////// | |
var makeBTree = function(){ | |
var newBTree = {}; | |
var root; | |
////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var nQueens = function(n){ | |
if(n === 1){ return 1; } | |
n = n - 1; | |
var | |
m = Math.ceil(n/2), | |
count = 0, | |
col = new Int8Array(n + 1), | |
maj = new Int8Array(n + n + 1), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is an example express middleware that can be inserted into any route that needs to be protected, assuming that authentication is done via JSON web tokens | |
var crypto = require('crypto'); | |
var verifyJWTToken = function(req, res, next){ | |
var secret = process.env.TOKEN_SECRET; | |
// 1. get the token from the headers. I'm going to go ahead and split up the three parts already | |
var token = req.headers['x-access-token'].split('.'); | |
// 2. Get the signature, and the rest of the token. Calculate the digest with HMAC-SHA256 so we can see if it matches the signature |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// here's a normal JavaScript constructor function | |
var Block = function(){ | |
this.width = 30; | |
this.height = 50; | |
this.otherthing = "whateverelse"; | |
}; | |
// these are class methods that all blocks inherit from | |
Block.prototype.doThing = function(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doctype html | |
html | |
head | |
title Nothing wrong with using Jade with Angular! | |
body(ng-app="app") | |
div(ng-controller="fooController") | |
h1 {{ title }} | |
p {{ body }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('app') | |
.factory('authentication', [ | |
'user', | |
function(user){ | |
return { | |
authentication: function(){ | |
return user.identify(); | |
} | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('app') | |
.factory('authentication', [ | |
'user', | |
function(user){ | |
return { | |
authentication: function(){ | |
return user.identify(); | |
} | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('app') | |
.factory('authentication', [ | |
'user', | |
'$state', | |
function(user, $state){ | |
return { | |
authenticate: function(protect){ | |
return user.identify() | |
.then(function(){ | |
return true; |
OlderNewer