Skip to content

Instantly share code, notes, and snippets.

@Kirens
Kirens / thoughts.tex
Created December 2, 2018 16:18
Things that cause trouble in tex
% Forgetting an unexpandable after advance has unpredictable errors
% creeping up when numbers are processed afterwards.
\advance\ThrottleCounter by -1%
\ifnum\the\ThrottleCounter=0%
#1%
\fi
% The above fails misserably if the counter is on 0 and the first
% argument happens to be a number, then it will be expanded to.
\advance\ThrottleCounter by -1#1
% which turns out to be
@Kirens
Kirens / ADT.js
Created November 13, 2018 05:53
WIP: Algebraic data types in JS
const ADT = cls => variations => {
let package = {}
package[cls] = class {}
variations.forEach(([name, ...args]) =>
package[cls][name] = function(...args) {
}
package[cls][name].name = name
package[cls][name].prototype = package[cls]
@Kirens
Kirens / brainfuck.sty
Created October 29, 2018 15:54
A brainfuck interpreter in TeX
\ProvidesPackage{brainfuck}[2018/10/29 v1.0 A package to provide a Brainfuck interpreter interface]
\def \IgnoreSpaceInCode{%
\endlinechar = 32\relax%
\catcode 9 = 9\relax%
\catcode 32 = 9\relax%
}
\def \AcknowledgeSpaceInCode{%
\endlinechar = 13\relax%
@Kirens
Kirens / layout.md
Last active August 19, 2019 20:42
A keyboard-layout for my laptop

My keyboard

 _______________________________________________
| [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ] |
| [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][____] |
| [__][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][___] |
| [___][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][_____] |
| [____][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][_______] |
| [ ] [ ][ ][_____________][ ][ ][ ][ ]EΞƎ[ ] |
@Kirens
Kirens / ex.js
Last active November 17, 2018 12:42
Exempel på JavaScript-kod med statisk typning som inte påverkar körbarhet
// Do some stuff to showcase different type signatures
// main :: () >> Promise Fetcher a
const main = () =>
whoAmI()
.catch(alerter('Could not determine who you are'))
.then(set('userName')(window))
.then(wait(5))
.then(randomName)
.then(iAmThis)
.catch(alerter('Could not update your name'))
@Kirens
Kirens / commands.sh
Created August 3, 2018 06:43
Forward Web trafic to other host with IPTABLES
sudo iptables -t nat -A PREROUTING -j DNAT -p tcp --dport 80 --to {{HOST}}:80
sudo iptables -t nat -A PREROUTING -j DNAT -p tcp --dport 443 --to {{HOST}}:443
### Explanation
# iptables [-t table] -[AD] chain rule-specification [options]
# table:
# `-t nat` - We want the rules to apply to the "nat" table; to the
# first packets of a connection
# operation:
# `-A` - We want to append the rule
# chain:
@Kirens
Kirens / reload.js
Created July 4, 2018 10:40
Abstracting away execution over reloads
// Function index
let preparableFunctions = {byName: {}, byFn: new WeakMap()}
let awaitingFn = {}
const mkPreparable = (name, fn) => {
const p = preparableFunctions
if(p.byName[name] || p.byFn.has(fn)) throw new Error('Naming collision')
p.byName[name] = fn
p.byFn.set(fn, name)
@Kirens
Kirens / script.js
Created June 9, 2018 16:51
Switch G-suite user (currently only for calendar)
// ==UserScript==
// @name Switch G user
// @version 1
// @grant none
// @include https://calendar.google.com/calendar/*
// ==/UserScript==
var changeUser = (domainRegex, domainBase) => idx => {
const href = location.toString()
if(!href.match(domainRegex)) return false
@Kirens
Kirens / ext.js
Created June 1, 2018 12:19
Avanza tools
// ==UserScript==
// @name Avanza tools
// @version 1
// @grant none
// ==/UserScript==
HTMLCollection.prototype.toArray = function(){ return Array.from(this) }
const realConcat = Array.prototype.concat
Array.prototype.concat = function() {
if(arguments.length) return realConcat.apply(this, arguments)
else return realConcat.apply([], this)
@Kirens
Kirens / keybinds.vimium
Last active March 26, 2018 11:21
Vimium config stuff
" Enable default keybindings
map <Space> passNextKey
" Options shortcut
" installation dependent. Solution?
map <c-o> createTab moz-extension://f0d12a45-b3ab-4963-a516-886319b12d85/pages/options.html
" Prevent accidental Ctrl-w
#map <c-w> scrollToTop "Doesn't work