Skip to content

Instantly share code, notes, and snippets.

View deepal's full-sized avatar

Deepal Jayasekara deepal

  • CompareTheMarket.com
  • London, United Kingdom
View GitHub Profile
@deepal
deepal / nodesec-hpp.js
Created February 18, 2016 11:36
nodesec-hpp
var hpp = require('hpp');
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlencoded({extended: false})); //body parser should be placed before using hpp
app.use(hpp());
app.get('/', function(req, res, next){
console.log('Query Parameters : ' + JSON.stringify(req.query));
{
"name": "My App",
"version": "0.0.0",
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.13.2",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
@deepal
deepal / nodesec-secrets-in-env.js
Last active February 18, 2016 18:07
nodesec-secrets-in-env
app.use(session({
name: 'SESS_ID',
secret: process.env.EXPRESS_SESSION_SECRET,
resave: false,
saveUninitialized: true,
cookie: {
secure: true,
httpOnly: true
}
}));
var express = require('express');
var http = require('http');
var app = express();
/*define routes here*/
var server = http.createServer(app);
server.listen(80, function(err){
if (err) {
@deepal
deepal / angular-inject.js
Created February 22, 2016 09:12
Using $inject to inject dependencies in AngularJS
angular.module('app')
.controller('MyController', MyController);
MyController.$inject = ['$scope', '$http', '$location'];
function MyController ($scope, $http, $location) {
// write controller function
}
@deepal
deepal / angular-routehelper.js
Created February 22, 2016 09:18
Using routeHelper to register angular routes
angular.module('app')
.run(['routeHelper', function(routeHelper){
routeHelper.configureRoutes(getRoutes());
}]);
function getRoutes() {
return [
{
url: '/',
config: {
// Nodejs encryption with GCM
// Does not work with nodejs v0.10.31
// Part of https://github.com/chris-rock/node-crypto-examples
var crypto = require('crypto'),
algorithm = 'aes-256-gcm',
password = '3zTvzr3p67VC61jmV54rIYu1545x4TlY',
// do not use a global iv for production,
// generate a new one for each encryption
iv = '60iP0h6vJoEa'
@deepal
deepal / mongod.conf
Created May 19, 2016 11:56
/etc/mongod.conf
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
security:
authorization: disabled
security:
authorization: disabled