Skip to content

Instantly share code, notes, and snippets.

@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";
#!/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 / 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 -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 / 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);
@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 / 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 / sort-by-ext
Last active June 9, 2023 03:50
Sort input lines by extension
#!/usr/bin/env python3
# Copyright (C) 2023 Andre Kugland
# This script is released under the MIT License.
"""
sort-by-ext: Sort input lines by extension.
Usage: sort-by-ext [-0]

Keybase proof

I hereby claim:

  • I am kugland on github.
  • I am kugland (https://keybase.io/kugland) on keybase.
  • I have a public key whose fingerprint is 6A62 5E60 E3FF FCAE B3AA 50DC 1DA9 3817 80CD D833

To claim this, I am signing this object:

@kugland
kugland / lineinfile
Created December 26, 2022 05:41
lineinfile, similar to the Ansible action, in Perl
#!/usr/bin/env -S perl -CSD
# Usage: lineinfile <regexp> <new_value> <file1> <file2> <file3> ...
use strict;
use warnings;
use utf8;
if (@ARGV < 3) {
die "Usage: $0 <regexp> <new_value> <file1> <file2> <file3> ..."