Skip to content

Instantly share code, notes, and snippets.

View lennym's full-sized avatar

Leonard Martin lennym

View GitHub Profile
@lennym
lennym / app.js
Created July 19, 2016 14:55
Express middleware mounting patterns
const app = require('express');
app.use(require('./default-middleware'));
app.use(require('./router'));
module.exports = app;
@lennym
lennym / s3.touch.js
Last active December 2, 2018 22:14
'use strict';
require('env2')('.env');
const AWS = require('aws-sdk');
const async = require('async');
const Progress = require('cli-progress');
AWS.config.region = 'eu-west-1';
const s3 = new AWS.S3();
const AWS = require('aws-sdk');
const assert = require('assert');
const kinesis = new AWS.Kinesis({ region: 'eu-west-1' });
function start () {
kinesis.describeStream({ StreamName: 'isearch' }, (err, result) => {
assert(!err);
console.log(result);
setInterval(write, 1000);
const a = {};
a.foo = 'bar';
console.log(a); // { foo: 'bar' }
const b = 'foo';
b += 'bar';
console.log(b); // 'foo'
var app = require('express')();
app.get('/foo', function (req, res, next) {
res.send(req.path);
// here req.path === '/foo'
});
app.use('/bar', function (req, res, next) {
res.send(req.path);
// here req.path === '/'
@lennym
lennym / mocha.js
Created July 1, 2015 12:04
mocha async setup example
var getApp = require('./main');
describe('App Tests', function () {
var app;
beforeEach(function (done) {
getApp(function (err, a) {
app = a;
done(err);
function requestHandler(req, res) {
fs.readFile('/my/file', function (err, file) {
if (err) {
res.status(500).send();
} else {
res.send(file);
}
});
}
11:22 AM <lennym> Morning all, I'm having some issues with node-sass and npm, but only in certain contexts. I was hoping to talk it through to see if I'm doing anything obviously stupid.
11:23 AM <lennym> I have a project, which has a module as a dev dependency - both depend on node sass, and both run node sass as part of a postinstall script
11:24 AM <lennym> Except the postinstall script fails in node-sass for the child module with an error of "Cannot find module semver" here - https://github.com/sass/node-sass/blob/v2.1.1/lib/extensions.js#L1
11:24 AM <lennym> When run not as a child dependency of the parent project it works fine.
11:24 AM <lennym> Both projects have the same (2.1.1) dependency of node-sass
11:25 AM <lennym> Now here's the kicker... it *only* fails as part of an npm install on our jenkins build server, I can't replicate locally.
11:26 AM <lennym> If anyone has any ideas or suggestions I'd be happy to hear them.
@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({
@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 {