Skip to content

Instantly share code, notes, and snippets.

View nknapp's full-sized avatar

Nils Knappmeier nknapp

View GitHub Profile
var _ = require('lodash')
function regex (strings, ...args) {
return new RegExp(String.raw(strings, ...args.map(_.escapeRegExp)))
}
var needle = '1*'
console.log('21111112'.match(regex`2${needle}2`)) // falsy
console.log('2221*1*222'.match(regex`2(${needle})+2`)) // truthy
@nknapp
nknapp / example.js
Created March 11, 2017 11:37
Concept for source-mapping the output of a Handlebars-template back to the template
var Handlebars = require('handlebars');
var LineCounter = require("line-counter");
var env = Handlebars.create();
function SourceMapCompiler() {
}
SourceMapCompiler.prototype = new Handlebars.JavaScriptCompiler();
SourceMapCompiler.prototype.appendToBuffer = function (source, location, explicit) {
@nknapp
nknapp / wipe-docker.sh
Created January 1, 2017 21:26
Clear the complete docker environment
#!/bin/bash
echo Killing all containers
for i in $( docker ps -q ) ; do
docker kill $i
done
echo Removing all containers
for i in $( docker ps -aq ) ; do
docker rm $i
@nknapp
nknapp / Dockerfile
Created October 30, 2016 20:15
Traefik setup as reverse-proxy with docker and letsencrypt
FROM traefik:camembert
ADD traefik.toml .
EXPOSE 80
EXPOSE 8080
EXPOSE 443
{
"name":"test",
"version":"3.14.15"
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="main.css">
<meta charset="UTF-8">
<title>Swagger Petstore</title>
</head>
<body>
<div class="container">
<h1>Swagger Petstore</h1>
@nknapp
nknapp / a+b=c
Last active August 29, 2015 14:14
// Let a,b and c be 3-digit numbers such that every digit 1 to 9
// occurs exactly once if all number are written in concatenation.
// For which number is a+b=c true.
// This is a riddle from a mathematics-book for fourth-graders. It is marked
// as "difficult, for students that are faster than others".
var buffer = [0,0,0,0,0,0,0,0,0];
function add(pos, callback) {