Skip to content

Instantly share code, notes, and snippets.

Avatar
🎻
practicing

Raitis Veinbahs siers

🎻
practicing
View GitHub Profile
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
@siers
siers / LensSuffix.hs
Created April 24, 2021 19:49
Lens Template Haskell data fields with suffix
View LensSuffix.hs
import Control.Lens.Internal.FieldTH (makeFieldOptics, LensRules(..))
import Language.Haskell.TH.Syntax (mkName, nameBase)
import Control.Lens.TH (DefName(..), lensRules)
data Field = { a :: Int, b :: Int }
makeFieldOptics lensRules { _fieldToDef = (\_ _ -> (:[]) . TopName . mkName . (++ "L") . nameBase) } ''Field
-- hopefully someone find this useful
@siers
siers / .gitignore
Last active October 22, 2020 20:53
my megasec parsers
View .gitignore
dist
.stack-work
View tar exclude test
#! /usr/bin/env bash
set -eu
pwd | grep -q '^/tmp'
cat > excl <<-EOF
a
b/*c*
./d
@siers
siers / redecorate.py
Created July 17, 2018 10:56
recursive chown uid/guid mapping for migrating ownership to LDAP
View redecorate.py
#!/usr/bin/env python
# recursive chown uid/guid mapping for migrating files' owners to
# the new LDAP ids by matching users' duplicate names in /etc/passwd and
# treating the upper ones (from `getent passwd` list) as the real ones
# Created around January, 2017
# raitis.veinbahs.lv
# This file may be freely used, modified, copied and repurposed. Public domain.