Skip to content

Instantly share code, notes, and snippets.

@stewhouston
stewhouston / is-ms-browser.js
Created May 28, 2016 05:34
Detect Internet Explorer/Edge with JavaScript userAgent string sniffing. Silly spoofers.
var isIE = (function() {
var ua = navigator.userAgent,
ieMatches = [/Edge\/[0-9\.]+$/, /MSIE/, /Trident\/[0-9\.]+/];
for(var i = 0, len = ieMatches.length; i < len; i++) {
if (ua.match(ieMatches[i])) {
return true;
}
}
@stewhouston
stewhouston / gulpfile.js
Created May 27, 2016 21:31
Various gulp tasks for managing and bundling an angular 2 app
'use strict';
const gulp = require('gulp');
const $ = require('gulp-load-plugins')();
const _ = require('lodash');
const fs = require('fs-extra');
const runSequence = require('run-sequence');
import { Route, RouteControllerDecorator as RouteController } from './lib/octv';
import { GamesService } from './services';
module.exports = (function() {
@RouteController({
providers: ['express']
})
class GamesController {
baseUrl:string = '/games';
gamesService:GamesService;
@stewhouston
stewhouston / gulpfile-ng-bundle-task.js
Created May 23, 2016 02:55
Example of a bundling task for Angular 2 with gulp (so as to reduce http/xhr requests.) Works in the context of a project created through angular-cli.
gulp.task('ng-bundle', function(done) {
process.chdir('dist');
let bundleFilename = 'app.bundle.js';
const Builder = require('systemjs-builder');
let builder = new Builder();
builder.loadConfig('system-config.js')
// @note start server with pm2 in production
module.exports = (function() {
const argv = require('yargs').argv;
const env = argv.env || process.env.NODE_ENV || 'dev';
const port = <number> argv.port || 3000;
var app = require('express')();
const octvConfig = require('./octv.environments')(env);
@stewhouston
stewhouston / ts-classfactory.ts
Last active May 20, 2016 00:50
Class factory decorator pattern in TypeScript. Used for dependency injection in Express.
export default function RouteController(decoratorParams:Object) {
var providers:any[];
if (Array.isArray(decoratorParams['providers'])) {
providers = decoratorParams['providers'].map((provider:string) => {
let p = require(provider);
return p;
});
}
@stewhouston
stewhouston / nginx.conf
Created May 19, 2016 05:22 — forked from turtlesoupy/nginx.conf
node.js upstream nginx config
http {
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;
proxy_temp_path /var/tmp;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_comp_level 6;
var RouteController = require('./lib/RouteController');
@RouteController({
providers: ['express', 'mongoose']
})
class Dota2Controller {
baseUrl:string = '/dota2';
routes:any;
constructor(private express, private mongoose) {
@stewhouston
stewhouston / atom-toggle-typescript-pane
Created May 17, 2016 17:16
Custom atom command to toggle the atom-typescript (TypeStrong) panel
# Atom Init Script (atom/init.coffee)
atom.commands.add 'atom-text-editor', 'custom:toggle-typescript-pane', ->
editor = atom.workspace.getActiveTextEditor()
tsPane = document.querySelector('.atomts')
if (!tsPane)
return
isHidden = tsPane.classList.contains('atomts-hidden')