Skip to content

Instantly share code, notes, and snippets.

Avatar

Nils Knappmeier nknapp

View GitHub Profile
View tic-tac-toe.html
<html>
<head>
<style>
h1 {
position: absolute;
display: block;
top: 50%;
left: 50%;
transform: rotate(30deg);
@nknapp
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 = 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.
@nknapp
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;
View bootprint-development.sh
# Some more dependencies
git clone git@github.com:bootprint/customize.git
git clone git@github.com:bootprint/customize-engine-handlebars.git
git clone git@github.com:bootprint/customize-engine-less.git
git clone git@github.com:bootprint/customize-write-files.git
git clone git@github.com:bootprint/bootprint.git
# Clone the repos
git clone git@github.com:bootprint/bootprint-openapi.git
git clone git@github.com:bootprint/bootprint-json-schema.git
@nknapp
nknapp / _watch-cpu-freq.md
Last active Feb 25, 2020
Set powersave/performance governor based on ac/battery status
View _watch-cpu-freq.md

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/watch-power-cpufreq.sh

and then run

@nknapp
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)
View 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:

View pipe-in-table.md
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, ...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 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.