Skip to content

Instantly share code, notes, and snippets.

@Kirens
Kirens / backend.hs
Last active December 4, 2022 12:36
TVmannen 2.0. Skynet version
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Lazy as BL
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import qualified Network.Wai as Wai
import qualified Network.Wai.Handler.Warp as Warp
import qualified Network.Wai.Middleware.RequestLogger as RequestLogger
import qualified Network.Wai.Middleware.Static as Static
import qualified Network.Wai.Parse as Parse
@Kirens
Kirens / install.sh
Last active July 18, 2022 08:43
raspberry-pi librespot
# Setup headless raspbian
# Install PulseAudio and vlc for http stream sinks
sudo apt install pulseaudio vlc
# Install librespot via raspotify, but disable raspotify
curl -sL https://dtcooper.github.io/raspotify/install.sh | sh
sudo systemctl disable raspotify.service
# Install librespot user service
@Kirens
Kirens / nginx.nix
Created December 1, 2021 14:33
Generate systemd service-files from nixos nginx configuration
{ nixpkgs ? import <nixpkgs> { }
, pkgs ? nixpkgs.pkgs
, lib ? pkgs.lib
, nixos ? import <nixpkgs/nixos>
}:
let
config = (nixos {
configuration.security.acme.certs."example.com".email = "webmaster@example.com";
configuration.services.nginx = {
enable = true;
@Kirens
Kirens / Fmt.idr
Created September 30, 2019 15:56 — forked from brendanzab/Fmt.idr
-- Based off https://www.youtube.com/watch?v=fVBck2Zngjo
module Fmt
%default total
data FPart
= FShow -- "{}" (Show a => a)
| FInt -- "{i}" (Int)
| FString -- "{s}" (String)
@Kirens
Kirens / safeConfigFromJSON.ts
Last active July 29, 2019 07:43
Demonstration of parsing to strict type from JSON
// Define our configuration as specific as possible
///////////////////////////////////////////////////
type Natural = number & { __nat__: void };
function isNatural(val: unknown): val is Natural {
return typeof val === "number" && val % 1 === 0 && val >= 0;
}
type Version = 1;
function isVersion(val: any): val is Version {
@Kirens
Kirens / gist:22ba0528a6d00e2d7a2d754b62707d69
Created January 29, 2019 09:43
Propositions in conditionals
// is :: (U String Constructor) ---> T --(Predicate for `object` being a `test`)--> Bool
const is = test => object =>
typeof test === 'string'
? typeof object === string // object is assured to be a string
: object instanceof test // Object can be anything but a string
const x = [1, 2, 3]
if ( is(Array)(x) ) {
// x is assured to be an array
x.push(5)
@Kirens
Kirens / overleaf_user_script.js
Created December 26, 2018 10:36
Overleaf vim controls - scroll, select files, etc.
// ==UserScript==
// @name Overleaf Vim File Select
// @namespace Violentmonkey Scripts
// @version 1
// @grant unsafeWindow
// @include https://www.overleaf.com/project/*
// @run-at document-idle
// ==/UserScript==
const getFileTree = () => document.getElementsByClassName('file-tree-inner')[0]
@Kirens
Kirens / vim.rc
Created December 24, 2018 08:51
Dissable arrow keys in vim
" I need to forget arrows
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
vnoremap <Up> <NOP>
vnoremap <Down> <NOP>
vnoremap <Left> <NOP>
vnoremap <Right> <NOP>
inoremap <Up> <NOP>
@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