Skip to content

Instantly share code, notes, and snippets.

View phaer's full-sized avatar
💭

Paul Haerle phaer

💭
View GitHub Profile
import json
import uuid
import subprocess
from pathlib import Path
age_identity = Path("~/.passage/identities").expanduser()
store_dir = Path("~/.passage/store").expanduser()
folders = []
items = []
@phaer
phaer / raw_tag.rb
Created June 11, 2011 19:11
Raw tag for jekyll. Keeps liquid from parsing text betweeen {% raw %} and {% endraw %}
module Jekyll
class RawTag < Liquid::Block
def parse(tokens)
@nodelist ||= []
@nodelist.clear
while token = tokens.shift
if token =~ FullToken
if block_delimiter == $1
end_tag
@phaer
phaer / build.sh
Last active April 12, 2023 11:54
dream2nix v1 api without flakes
$(nix-build -A packages.odoo.config.lock.refresh --no-out-link)/bin/refresh
nix-build -A packages.odoo
@phaer
phaer / parse-currentTime.nix
Created March 15, 2023 23:09
parse-currentTime.nix
# https://stackoverflow.com/questions/7136385/calculate-day-number-from-an-unix-timestamp-in-a-math-way
# https://howardhinnant.github.io/date_algorithms.html#civil_from_days
let
t = builtins.currentTime;
z = t / 86400 + 719468;
era = (if z >= 0 then z else z - 146096) / 146097;
doe = (z - era * 146097);
y' = (yoe) + era * 400;
doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365;
@phaer
phaer / writeScript.nix
Created December 5, 2022 21:38
nix: writeScript without stdenv
{ name ? "hello"
, text ? "echo 'Hello World'"
, pkgs ? import <nixpkgs> {}
}:
builtins.derivation {
inherit name;
inherit (pkgs) system;
builder = "${pkgs.busybox}/bin/busybox";
args = [
"sh"
@phaer
phaer / fetch-from-store.sh
Created August 13, 2022 09:21
Fetch a file from a nix binary cache via HTTP, given its store path
#!/usr/bin/env bash
# TODO: run in nix shell gitlab:abstract-binary/nix-nar-rs, nix-shell does not support
# flakes, nix shell no shebangs atm.
STORE_PATH="/nix/store/4q7ij8ivy09vbhini8j0gzd7f77z0bwn-disk-image"
FILE_NAME="nixos.root.qcow2"
CACHE_URL="https://nix-dabei.cachix.org"
HASH="$(echo "$STORE_PATH" | sed 's|^/nix/store/\([^-]*\)-.*$|\1|')"
NAR_INFO_URL="$CACHE_URL/$HASH.narinfo"
@phaer
phaer / secrets.nix
Last active January 14, 2022 09:47
nixos-secret-templates
{ pkgs, lib, config, ... }:
let
cfg = config.my.secrets;
makeSecretServiceUnit = name: value:
lib.nameValuePair "secret-${value.secret}" {
description = "template for secret ${value.secret}";
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
@phaer
phaer / convert.py
Created August 15, 2018 03:47
kubernetes open api to hcl2 spec
import sys
import json
from collections import OrderedDict
from contextlib import contextmanager
def resolve_json_pointer(spec, reference):
prefix, definitions, name = reference.split('/')
return spec.get(definitions).get(name)
@phaer
phaer / org-metadata.py
Created January 3, 2021 12:42
Workaround for pandocs org-parser not handling generic multi-line metadata keys.
#!/usr/bin/env python3
"""
Pandocs Org-Parser does not handle generic multi-line metadata keys. Only
their last line ends up in the AST and so this can't be solved (easily) with
lua filters.
We use python to extract org metadata keys before the first non-metadata line
and output them in YAML for use with pandoc's --metadata-file. E.g.
#+TITLE: Letter
@phaer
phaer / mpd-youtube-dl.py
Last active September 28, 2020 22:52
A simple script to pipe URIs through youtube-dl and into musicpd.
#!/usr/bin/env python3
"""
A simple script to pipe URIs through youtube-dl and into musicpd.
pip3 install python-mpd2 youtube-dl
"""
import sys
import mpd
import youtube_dl