Skip to content

Instantly share code, notes, and snippets.

View lennym's full-sized avatar

Leonard Martin lennym

View GitHub Profile
@lennym
lennym / logger.js
Created November 25, 2014 11:28
Logging with Winston
var winston = require('winston');
var config = require('./config');
var logger = new winston.Logger({
transports: [
new winston.transports.Console({ colorize: true }),
new winston.transports.File({ filename: config['app-log'], json: false })
],
exceptionHandlers: [
@lennym
lennym / test.js
Last active August 29, 2015 14:10
// example test script for module with http.get
// uses sinon, chai and mocha.
var Module = require('./my-module-that-does-http');
var http = require('http');
describe('Module', function () {
beforeEach(function () {
@lennym
lennym / json-linter.js
Created December 8, 2014 14:53
json-linter.js
var fs = require('fs'),
path =require('path');
var dir = process.argv[2];
if (!dir) {
console.error('Folder path must be defined.');
console.log('Usage: node json-linter.js /path/to/test');
process.exit(1);
}
@lennym
lennym / hack.js
Created December 11, 2014 15:09
HTTPS
var https = require('https');
var getLatestCoreVersion = function(major, cb) {
var json = '';
var req = https.get({
host: 'api.github.com',
path: '/repos/mozu/core-theme/releases',
headers: {
'User-Agent': 'thmaa',
'content-length': 0,
},
@lennym
lennym / gist:8dcd3ceafd30b9305be0
Created February 25, 2015 14:16
package json snippet
...
"karma": "0.12.24",
"karma-browserify": "0.2.1",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "0.1.5",
"karma-firefox-launcher": "0.1.3",
"karma-mocha": "0.1.9",
"karma-phantomjs-launcher": "0.1.4",
"karma-sinon-chai": "0.2.0",
...
@lennym
lennym / test.js
Created April 9, 2015 15:51
Example middleware test
var middleware = require('./my-middleware')
describe('middleware', function () {
var req, res;
beforeEach(function () {
req = {
session: { username: 'lennym' }
},
res = {}
@lennym
lennym / index.js
Created April 24, 2015 11:26
console.log calls inspect
var app = {
inspect: function () {
return 'a kitten!';
}
};
console.log(app);
@lennym
lennym / routers.js
Last active August 29, 2015 14:20
Nested routers
var express = require('express');
var app = express();
var jobs = express.Router();
var properties = express.Router();
var property = express.Router();
jobs.route('/:id')
.get(function (req, res, next) {
@lennym
lennym / gist:e1b063d40e94027b84fb
Last active August 29, 2015 14:21
url normalisation middleware
var url = require('url');
app.use(function (req, res, next) {
if (req.path.indexOf('&') > -1) {
var path = req.path.split('&')[0];
res.redirect(url.format({
pathname: path,
query: req.query
}));
} else {
@lennym
lennym / sass
Created June 3, 2015 10:27
node-sass build script
#!/usr/bin/env node
var sass = require('node-sass'),
path = require('path'),
fs = require('fs');
var src = path.resolve(__dirname, '../assets/sass/app.scss'),
out = path.resolve(__dirname, '../public/stylesheets/app.css');
sass.render({