Skip to content

Instantly share code, notes, and snippets.

View nknapp's full-sized avatar

Nils Knappmeier nknapp

View GitHub Profile
@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) {
<!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>
{
"name":"test",
"version":"3.14.15"
}
@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) {
First Header Second Header
Content from cell 1 Content from cell 2
Content in the first column Content in the `find *
@nknapp
nknapp / keybase.md
Created May 24, 2017 21:19
keybase.md

Keybase proof

I hereby claim:

  • I am nknapp on github.
  • I am nknapp (https://keybase.io/nknapp) on keybase.
  • I have a public key ASBc1DN469TlP5kG_R1r8OKyyQxfxvztA9b1dkpyd8zywQo

To claim this, I am signing this object:

@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 / phashBuffer.js
Last active March 20, 2018 23:02
searching phashs
// Precompute the number of matching bits by the xor-result of two bytes
const matchingBitsFromXor = []
for (let i = 0; i < 256; i++) {
matchingBitsFromXor[i] = countMatchingBits(i)
}
class PhashBuffer {
constructor (bytesPerHash, maxSize) {
this.buffer = Buffer.alloc(bytesPerHash * maxSize)
@nknapp
nknapp / logger-spec.ts
Last active June 4, 2018 19:53
A logger that I didn't want to throw away, but I'm currently not needing it.
import { expect } from "chai";
import { Writable } from "stream";
import { logLevel, LogManager, toStream } from "../../src/utils/logger";
describe("The logger", () => {
describe("The 'for'-function", function() {
const logEntries: any[] = [];
const log = new LogManager();
let stream: Writable;
@nknapp
nknapp / performance-test.js
Last active October 5, 2018 21:05
Should we really use anonymous functions as callback
function measure (description, fn) {
console.log('Running ' + description);
let start = Date.now();
fn(100000000);
console.log(`Took ${Date.now() - start}ms\n`);
}
/**
* The scenario is: We want to call a lot of callbacks.
* Which is faster: The usual anonymous callback.