Skip to content

Instantly share code, notes, and snippets.

View siers's full-sized avatar
:octocat:

Raitis Veinbahs siers

:octocat:
View GitHub Profile
@siers
siers / NaiveCopy.hs
Created January 4, 2024 12:51
Naive directory tree copy with full contents in memory and using recursion schemes (cata/anaM)
View NaiveCopy.hs
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UnicodeSyntax #-}
@siers
siers / leveldb-cli.nix
Created December 22, 2023 22:30
leveldb-cli nix buildGoModule
View leveldb-cli.nix
{ fetchFromGitHub, buildGoModule }:
buildGoModule {
name = "leveldb-cli";
vendorHash = "sha256-xM32ynbK8rF6JZty4701A+g6WxHOPx+frBngVIXizV4=";
src = fetchFromGitHub {
owner = "liderman";
repo = "leveldb-cli";
rev = "4233523f321208dfda6dce4908d407ad6ee39b0c";
hash = "sha256-BwxCpBw+ChpENc44SAXKoQKXs4ckI1Fayy9Mq55KWiw=";
@siers
siers / flake.nix
Last active October 11, 2023 08:05
printing out a lamb
View flake.nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-23.05";
};
outputs = { self, nixpkgs }:
with nixpkgs.legacyPackages.x86_64-linux;
let
system = "x86_64-linux";
@siers
siers / bank-statement-parser.sh
Last active June 2, 2023 06:48
Swedbank bank statement parser
View bank-statement-parser.sh
#! /usr/bin/env zsh
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p python36Packages.csvkit
# map <f9> :%!./parse 2>/dev/null <CR>
summer() {
(echo "Saņēmējs/Maksātājs,Summa,Datums"; grep -v "Summa,Datums") | \
csvsql --tables input --query 'SELECT SUM("Summa")/100.0 FROM input'
View ncdu-cache
#!/usr/bin/env zsh
# create or use ncdu's output from cache, then open ncdu
set -eu
sanit-path() { echo "$(tr / : <<< "$1" | tr -cd '0-9a-z\-.:')"; }
cache="$HOME/data/cache/ncdu" # RUN mkdir yourself!
dir="$1"; shift
@siers
siers / wait-while-idle.rb
Created September 8, 2016 10:39
Wait while xprintidle increases predictably thereby waiting until activity has been observed in the xorg
View wait-while-idle.rb
#!/usr/bin/env ruby
if %x{type xprintidle &> /dev/null; echo $?}.strip == '1'
raise 'xprintidle not found'
end
def idle
%x{xprintidle}.to_i
end
@siers
siers / index.html
Last active March 6, 2022 12:22
mandelbrot set with smoothing
View index.html
<!-- original: https://jsfiddle.net/poetix/KtCnB/ -->
<!-- testing hypothesis for generating: https://twitter.com/matthen2/status/1498717789233758222 -->
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<canvas width="500px" height="500px" id="canvas"></canvas>
<input type="range" id="iterations" name="iterations" min="0" max="100" value="50" step="1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
@siers
siers / yourkit.nix
Last active September 7, 2021 15:10
YourKit Java profiler Nix/NixOS package
View yourkit.nix
{ stdenv, fetchzip, zlib, openjdk8, openjdk11, version ? "v2019" }:
# https://www.yourkit.com/docs/java/help/running_profiler.jsp
let
versions = {
v2019 = {
date = "2019.1";
buildnr = "b133";
sha256 = "06p8y0mmyfrzjk5jz783gcfjsq6mk4rqddbqxarkkar7va5w5vk6";
@siers
siers / Supergraphs.hs
Last active June 8, 2021 09:02
Lattice joining graph connected components by their partition order
View Supergraphs.hs
module Main where
import Algebra.PartialOrd (PartialOrd(..))
import Data.Bifunctor (bimap)
import Data.Foldable (for_)
import Data.Function (on)
import Data.List.Extra (groupSortOn)
import Data.List (sortOn)
import Data.Set (Set)
import qualified Data.POSet as POSet
@siers
siers / Gamma.rb
Last active April 24, 2021 20:20
Plays from sol to sol.
View Gamma.rb
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# Primitive NoteFactory.
# http://en.wikipedia.org/wiki/Piano_key_frequencies
T = 44000
class NoteFactory
attr_accessor :notes, :notes_in_octave