Skip to content

Instantly share code, notes, and snippets.

View abathur's full-sized avatar
🦖

Travis A. Everett abathur

🦖
View GitHub Profile
@arianvp
arianvp / .envrc
Last active April 11, 2024 19:27
Use nix flakes with private github deps
#!/bin/sh
#If already set (e.g. in github actions); use that instead
if [ -z "$GITHUB_TOKEN" ]; then
nix run nixpkgs#gh auth status || nix run nixpkgs#gh auth login
GITHUB_TOKEN="$(nix run nixpkgs#gh auth token)"
export GITHUB_TOKEN
fi
NIX_CONFIG="access-tokens = github.com=$GITHUB_TOKEN"

A funky shell thingy that I've never seen before

So you're in posix sh and you want to do the equivalent of this in bash:

foo | tee >(bar) >(baz) >/dev/null

(Suppose that bar and baz don't produce output. Add redirections where needed if that's not the case.)

@Sidneys1
Sidneys1 / stail.sh
Created January 26, 2023 20:00
Short-Tail
#!/usr/bin/env bash
HELP="Usage: $0 [-n LINES] [-p PREFIX] [-w] [-h]
Continuously displays the last '-n' lines of 'stdin'.
Parameters:
-n Number of lines to display (default: 5).
-p PREFIX Prefix lines with 'PREFIX'.
-w Preserve blank lines (default: false).
-h Display this help

Nixpkgs Pivots

We have a number of problems that currently require full rebuilds of nixpkgs:

  • glibc needs to find third-party nss modules
  • cacerts needs to contain custom CA's from enterprises
  • tzdata just changed frequently
  • locales

Interestingly, Nix's deep pinning of cacerts and tzdata gets in the way of Nix's promise of packages working over the long term in an archival sense:

@rawiriblundell
rawiriblundell / SH_LIBPATH
Last active January 15, 2022 19:44
SH_LIBPATH bootstrap
# shellcheck shell=ksh
# If SH_LIBPATH is not set or null, then we try to build it
if [ -z "${SH_LIBPATH+x}" ] || [ "${#SH_LIBPATH}" -eq "0" ]; then
for _path in /usr/local/lib/sh "${HOME}"/.local/lib/sh; do
[ -d "${_path}" ] && SH_LIBPATH="${SH_LIBPATH}:${_path}"
done
fi
unset -v _path
# Remove any leading colons from the construction process and export
SH_LIBPATH="${SH_LIBPATH#:}"
@m-radzikowski
m-radzikowski / script-template.sh
Last active April 25, 2024 18:43
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]

Comments on optimizations around string concatenation.

Note: The code links are to CPython 3.8.5, the most recent release when this was written.

I was recently asked about a performance optimization in CPython around using += and + for string objects. As some people may already know, if you use += or + a string, it can sometimes be just as fast as ''.join. The question was to explain when that optimization couldn't be performed.

We will be going through the following example scenarios:

#!/usr/bin/awk -f
# This program is a copy of guff, a plot device. https://github.com/silentbicycle/guff
# My copy here is written in awk instead of C, has no compelling benefit.
# Public domain. @thingskatedid
# Run as awk -v x=xyz ... or env variables for stuff?
# Assumptions: the data is evenly spaced along the x-axis
# TODO: moving average
# typed: true
# frozen_string_literal: true
require('dev')
require('fileutils')
module Dev
module Helpers
class APFSVolume
extend(T::Sig)