Skip to content

Instantly share code, notes, and snippets.

@kugland
kugland / ellipsize.zsh
Last active January 31, 2023 21:32
Ellipsize path: function for Zsh (used in https://github.com/kugland/my-zshrc)
# Ellipsizes a path to display it in a limited space.
function ellipsize() {
(( ${#1} <= 40 )) && { print -r -- $1; return } # If the path is short enough, just return it.
local array=(${(s:/:)1}) # Split the path into an array.
local head=() tail=() # The head and tail of the path.
local prefix='' # '/' if the path is absolute, '' otherwise.
[[ ${1[1]} == '/' ]] && prefix='/' # If the path is absolute, set the prefix.
local next=tail # The next part of the path to be added.
local result # The result.
local elm # The current element being processed.
@kugland
kugland / open-whatsapp
Created February 4, 2023 04:34
Open WhatsApp from the shell with Termux
#!/data/data/com.termux/files/usr/bin/env lua
-- Escape a string for use in a shell command
local function shell_escape(args)
local ret = {}
local s
for _, a in pairs(args) do
s = tostring(a)
if s:match("[^A-Za-z0-9_/:=-]") then
s = "'" .. s:gsub("'", "'\\''") .. "'"
@kugland
kugland / cuefactor.pl
Created March 13, 2023 05:35
Multiply the time values in a CUE file by a factor.
#!/usr/bin/env -S perl -CSDA
# Multiply the time values in a CUE file by a factor.
use strict;
use warnings;
use utf8;
use autodie;
use Getopt::Long qw(:config posix_default no_ignore_case gnu_compat);
#!/usr/bin/env -S perl -CSDA
use 5.03;
use strict;
use warnings;
use utf8;
use open ':std', ':encoding(UTF-8)';
use URI;
use IPC::Open2;
@kugland
kugland / shell.nix
Created December 2, 2023 18:26
shell.nix for ffsubsync
{ pkgs ? import <nixpkgs> { } }:
let
audiotok = with pkgs.python3Packages; buildPythonPackage rec {
pname = "auditok";
version = "0.1.5";
src = fetchPypi {
inherit pname version;
sha256 = "sha256-HNsw9VLP7XEgs8E2X6p7ygDM47AwWxMYjptipknFig4=";
};
propagatedBuildInputs = [
#!/usr/bin/env bash
THIS_SCRIPT="$(realpath "$0")"
set -eu -o pipefail
build_container() {
CONTEXT="$(mktemp -d)"
trap 'rm -rf "$CONTEXT"' EXIT
sed -nE '/^# INCIPIT DOCKERFILE/,$p' < "$THIS_SCRIPT" > "$CONTEXT/Dockerfile"
@kugland
kugland / invidious.nix
Last active April 30, 2024 04:07
Invidious’s Nix configuration (generated from it’s docker-compose.yml)
{
pkgs,
lib,
...
}: let
listenHost = "127.0.0.1";
listenPort = 3000;
hmac_key = "0mwSVDxp8YhEuPvuxsUCoqhZBDQOys4U";
repo = fetchGit {
url = "https://github.com/iv-org/invidious";