Skip to content

Instantly share code, notes, and snippets.

@lierdakil
lierdakil / gitlab-math.lua
Last active April 9, 2023 08:15
Pandoc filter to parse GitLab math
function Math(el)
if el.mathtype == "InlineMath" then
if el.text:sub(1,1) == '`' and el.text:sub(#el.text) == '`' then
local text = el.text:sub(2,#el.text-1)
return pandoc.Math(el.mathtype, text)
else
local cont = pandoc.read(el.text)
return { pandoc.Str("$") } .. cont.blocks[1].content .. { pandoc.Str("$") }
end
end
@lierdakil
lierdakil / pollkeys.cpp
Created December 10, 2018 19:25
Linux polling all key event devices for key presses (minimalist example)
// Note: uses C++17 fs features; build with
// g++ -std=c++17 event-reader.cpp -lstdc++fs
//
// Licensed under the following terms:
// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
// Version 2, December 2004
//
// Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
//
// Everyone is permitted to copy and distribute verbatim or modified
@lierdakil
lierdakil / example.ts
Last active September 19, 2022 13:28
An example of Functor in TypeScript. You can run this on https://www.typescriptlang.org/play/
interface Functor<T> {
map<U>(f: (x: T) => U): Functor<U>
}
class Box<T> implements Functor<T> {
value: T
constructor(x: T) {
this.value = x
}
map<U>(f: (x: T) => U): Box<U> {
@lierdakil
lierdakil / texsvg.hs
Last active February 19, 2022 07:29
Pandoc filter to convert math to inline svg using latex and dvisvgm
{-# LANGUAGE OverloadedStrings #-}
import Text.Pandoc.JSON
import System.Directory
import System.FilePath ((</>))
import qualified Data.Hash.MD5 as MD5
import qualified Data.Text as T
import System.IO.Temp
import System.Process
import Control.Monad (unless)
#!/usr/bin/env ts-node
const path = require('path')
const fs = require('fs')
if (!process.argv[2]) {
process.stderr.write(`Usage: ${process.argv[1]} <filename>\n`)
return -1
}
const filePath = path.join(process.cwd(), process.argv[2])
@lierdakil
lierdakil / madoko.py
Last active August 26, 2020 01:23
A simple script to make madoko play with pipes
#!/usr/bin/env python
import tempfile
import sys
import subprocess
import os
import errno
# Make temp. file for input
inp = tempfile.NamedTemporaryFile(suffix='.mdk',mode='wb',dir=os.getcwd())
@lierdakil
lierdakil / apod.ts
Created June 15, 2020 03:38
Downloads NASA Astronomy Picture of the Day and displays it as the background using feh
#!/usr/bin/env -S deno run --allow-net=api.nasa.gov,apod.nasa.gov --allow-env --allow-write=${HOME}/.apodwallpaper --allow-run
// Filename: apod.ts
// Purposes: Downloads NASA Astronomy Picture of the Day and displays it as the background using feh
// Author(s): Nikolay "Lierdakil" Yakimov https://github.com/lierdakil
// !!! Replace this with your NASA API key; go to https://api.nasa.gov/ to get one
const api_key = 'DEMO_KEY'
// Read home variable
@lierdakil
lierdakil / checkers.cpp
Last active May 11, 2020 15:31
A slightly generalized optimized solver for Matt Parker's coin puzzle in C++17 https://www.think-maths.co.uk/coin-puzzle
#include <array>
#include <boost/dynamic_bitset/dynamic_bitset.hpp>
#include <future>
#include <iomanip>
#include <iostream>
#include <stdexcept>
#include <utility>
#include <vector>
enum class St { Empty, Occupied };
@lierdakil
lierdakil / .ccls
Last active February 10, 2020 01:47
Enables Razer BlackWidow 2013 macro keys in Linux
clang
-I/usr/include/libusb-1.0
@lierdakil
lierdakil / .gitignore
Last active January 14, 2020 12:33
Minimal typescript test project
node_modules