Skip to content

Instantly share code, notes, and snippets.

View chklauser's full-sized avatar

Christian Klauser chklauser

View GitHub Profile
@chklauser
chklauser / arbalest.kanata.kbd
Created December 30, 2024 14:06
Kanata Keymap for home row modifiers on and a nav cluster
#| --------------------------------------------------------------------------
KMonad: US ansi 100% template
This file contains the `defsrc` configuration for a standard US-ansi 100%
keyboard. Modelled on a standard DAS-keyboard 100%. Copy out the 'defsrc'
layer to start your own keyboard configuration. Copy out the `deflayer`
template to easily start a new layer with matching `transparent` buttons.
// Task builder for F# that compiles to allocation-free paths for synchronous code.
//
// Originally written in 2016 by Robert Peele ([email protected])
// New operator-based overload resolution for F# 4.0 compatibility by Gustavo Leon in 2018.
// Revised for insertion into FSharp.Core by Microsoft, 2019.
//
// Original notice:
// To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights
// to this software to the public domain worldwide. This software is distributed without any warranty.
//
@chklauser
chklauser / lk.ps1
Created January 31, 2022 22:13
Powershell version of my favorite custom bash function: 'lk' (look; shows a thing; decides how to show it based on the path/file extension)
New-Module -Name Lk -ScriptBlock {
[Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem')
if (-not (Get-Command -ErrorAction SilentlyContinue rich)) {
Write-Error '`rich` not installed. See https://github.com/Textualize/rich-cli'
}
if (-not (Get-Command -ErrorAction SilentlyContinue less)) {
Write-Error '`less` not installed. `scoop install less` maybe?'
}
function Show-Item {
param(
@chklauser
chklauser / ChunkedStreams.java
Last active May 2, 2022 15:22
A Java stream combinator that splits a stream into chunks of a fixed size. Last chunk in the stream might be smaller than the desired size. Ordering guarantees depend on underlying stream.
public final class ChunkedStreams {
private ChunkedStreams(){}
@SuppressWarnings("SameParameterValue")
public static <T> Stream<List<T>> chunks(Stream<T> sourceStream, int size) {
var source = sourceStream.spliterator();
return StreamSupport.stream(new Spliterator<>() {
final List<T> buf = new ArrayList<>();
@Override
public boolean tryAdvance(Consumer<? super List<T>> action) {
@chklauser
chklauser / lk.bash
Created April 4, 2016 07:21
Bash lk: call `less` or `ls -l` depending on context
# Bash function that calls `less` and `ls -l` depending on whether
# the target is a file or a directory. Surprisingly pleasant to use.
function lk {
local p
if [[ $# -lt 1 ]] ; then
p='.'
else
p="$1"
fi
#!/bin/bash
# Simple form
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# More correct/robust form, if you have time
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
@chklauser
chklauser / env_template.sh
Last active November 9, 2015 16:10
Poor man's bash template
_fill_in() {
perl -p -e 's/\$\{([^}]+)\}/defined $ENV{$1} ? $ENV{$1} : "\${$1}"/eg' "${1}"
}
# usage
export MY_VAR=15
_fill_in "my_file.tmpl" > "my_file"
@chklauser
chklauser / XorLinkedList.cs
Created August 10, 2015 20:18
XOR linked list in pure C#
// Proof-of-concept XorLinkedList
// Mostly untested! Do not use in serious code!
// NO WARRANTIES AT ALL!
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
@chklauser
chklauser / .gitconfig
Created August 3, 2015 08:29
Nice git log
[alias]
lg1 = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
lg = !"git lg1"
#!/bin/bash
export AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY
export AWS_SECRET_ACCESS_KEY=YOUR_SECRET_ACCESS_KEY
export PASSPHRASE=YOU_PASSHRASE
# directories, space separated
SOURCE="/home/thomas/backup /home/thomas/bin /home/thomas/documents"
BUCKET=s3+http://mybucket
LOGFILE=/home/thomas/tmp/duplicity.log
# set email to receive a backup report