Skip to content

Instantly share code, notes, and snippets.

View stefanwalther's full-sized avatar
🏠
Working from home

Stefan Walther stefanwalther

🏠
Working from home
View GitHub Profile
@stefanwalther
stefanwalther / version_compare.js
Last active August 29, 2015 14:01 — forked from TheDistantSea/version_compare.js
Version Compare (js)
/**
* Compares two software version numbers (e.g. "1.7.1" or "1.2b").
*
* This function was born in http://stackoverflow.com/a/6832721.
*
* @param {string} v1 The first version to be compared.
* @param {string} v2 The second version to be compared.
* @param {object} [options] Optional flags that affect comparison behavior:
* <ul>
* <li>

Easiest Table of Contents possible

In .verb.md where you want to inject the TOC:

<!-- toc -->

Done!

@stefanwalther
stefanwalther / QRS-Listapps.js
Created September 30, 2015 15:04 — forked from mindspank/QRS-Listapps.js
QRS-Listapps.js
/**
* Connects to the QRS API (REST based) using certificates.
* See this article for more information about connecting to QRS https://help.qlik.com/sense/2.0/en-us/developer/Subsystems/RepositoryServiceAPI/Content/RepositoryServiceAPI/RepositoryServiceAPI-Connect-API.htm
*
*/
var https = require('https');
var fs = require('fs');
@stefanwalther
stefanwalther / Enum.es6.js
Created October 16, 2015 15:08 — forked from xmlking/Enum.es6.js
JavaScript Enums with ES6, Type Checking and Immutability
export class EnumSymbol {
sym = Symbol.for(name);
value: number;
description: string;
constructor(name: string, {value, description}) {
if(!Object.is(value, undefined)) this.value = value;
if(description) this.description = description;
@stefanwalther
stefanwalther / CodeDeploy Policy
Created January 8, 2016 23:41 — forked from flomotlik/CodeDeploy Policy
Amazon IAM Policies for Codeship
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"codedeploy:RegisterApplicationRevision",
"codedeploy:GetApplicationRevision"
],
"Resource": [
@stefanwalther
stefanwalther / 1. handlebars-subexpression.html
Created March 8, 2016 18:31 — forked from jonschlinkert/1. handlebars-subexpression.html
Very powerful combination! Four helpers are used here: `each`, `expand`, `markdown` and `inline`.
{{#each (expand 'content/*.md')}}
{{#markdown}}
{{inline .}}
{{/markdown}}
{{/each}}
@stefanwalther
stefanwalther / handlebars-helper-x.js
Created June 9, 2016 22:33 — forked from akhoury/handlebars-helper-x.js
Handlebars random JavaScript expression execution, with an IF helper with whatever logical operands and whatever arguments, and few more goodies.
// for demo: http://jsbin.com/jeqesisa/7/edit
// for detailed comments, see my SO answer here http://stackoverflow.com/questions/8853396/logical-operator-in-a-handlebars-js-if-conditional/21915381#21915381
/* a helper to execute an IF statement with any expression
USAGE:
-- Yes you NEED to properly escape the string literals, or just alternate single and double quotes
-- to access any global function or property you should use window.functionName() instead of just functionName()
-- this example assumes you passed this context to your handlebars template( {name: 'Sam', age: '20' } ), notice age is a string, just for so I can demo parseInt later
<p>
{{#xif " this.name == 'Sam' && this.age === '12' " }}
@stefanwalther
stefanwalther / 0_reuse_code.js
Created June 25, 2016 18:43
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@stefanwalther
stefanwalther / logger.es6
Created November 26, 2016 00:21 — forked from daniloborges/logger.es6
A simple node module that makes console.log/error/warn/debug/time statements log through winston (simply include at the beginning of your app) ES5/ES6
import * as winston from 'winston';
import * as path from 'path';
let logger = new winston.Logger();
export default {
middleware(req, res, next){
console.log('verbose', req.method, req.url, res.statusCode);
next();
}
@stefanwalther
stefanwalther / mongoose.js
Created December 17, 2016 22:22 — forked from bayleedev/mongoose.js
A better syntax for mongoose instance and static methods.
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/foobar');
// bootstrap mongoose, because syntax.
mongoose.createModel = function(name, options) {
var schema = new mongoose.Schema(options.schema);
for (key in options.self) {
if (typeof options.self[key] !== 'function') continue;
schema.statics[key] = options.self[key];
}