Skip to content

Instantly share code, notes, and snippets.


Nils Knappmeier nknapp

View GitHub Profile
View tic-tac-toe.html
h1 {
position: absolute;
display: block;
top: 50%;
left: 50%;
transform: rotate(30deg);
nknapp / performance-test.js
Last active Oct 5, 2018
Should we really use anonymous functions as callback
View performance-test.js
function measure (description, fn) {
console.log('Running ' + description);
let start =;
console.log(`Took ${ - start}ms\n`);
* The scenario is: We want to call a lot of callbacks.
* Which is faster: The usual anonymous callback.
nknapp / logger-spec.ts
Last active Jun 4, 2018
A logger that I didn't want to throw away, but I'm currently not needing it.
View logger-spec.ts
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;
# Some more dependencies
git clone
git clone
git clone
git clone
git clone
# Clone the repos
git clone
git clone
nknapp /
Last active Feb 25, 2020
Set powersave/performance governor based on ac/battery status

This setup switches to "powersave" if the battery is lower than 75% and to "performance" if it is above and charging.

Copy the files to

  • /etc/systemd/system/watch-power-cpufreq.service
  • /usr/local/bin/

and then run

nknapp / phashBuffer.js
Last active Mar 20, 2018
searching phashs
View phashBuffer.js
// 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)

Keybase proof

I hereby claim:

  • I am nknapp on github.
  • I am nknapp ( on keybase.
  • I have a public key ASBc1DN469TlP5kG_R1r8OKyyQxfxvztA9b1dkpyd8zywQo

To claim this, I am signing this object:

First Header Second Header
Content from cell 1 Content from cell 2
Content in the first column Content in the find * &#124; grep "test" second column
View regex-template-literal.js
var _ = require('lodash')
function regex (strings, ...args) {
return new RegExp(String.raw(strings,
var needle = '1*'
console.log('21111112'.match(regex`2${needle}2`)) // falsy
console.log('2221*1*222'.match(regex`2(${needle})+2`)) // truthy
nknapp / example.js
Created Mar 11, 2017
Concept for source-mapping the output of a Handlebars-template back to the template
View example.js
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) {
You can’t perform that action at this time.