Skip to content

Instantly share code, notes, and snippets.

View abathur's full-sized avatar
🦖

Travis A. Everett abathur

🦖
View GitHub Profile
@jahio
jahio / .profile
Created January 3, 2017 11:05
Some useful aliases for installing and working with NixOS
#!/usr/bin/env $SHELL
alias lsblk="lsblk -o MODEL,VENDOR,NAME,LABEL,SIZE,MOUNTPOINT,FSTYPE"
alias gramps="nix-env -p /nix/var/nix/profiles/system --list-generations"
alias nixos-rebuild="nixos-rebuild -j 6 --cores 8"
#
# -j is how many "jobs" or simultaneous computational processes run in tandem
# --cores is how many CPU cores you want to use
# How do you get these values? `cat /proc/cpuinfo` and look at the number of
# returned "CPUs". They're zero indexed, so if you get the last one as object
# number seven (7), you have 8 cores.
# typed: true
# frozen_string_literal: true
require('dev')
require('fileutils')
module Dev
module Helpers
class APFSVolume
extend(T::Sig)
@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#:}"

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:

@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:

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.)

@lizthegrey
lizthegrey / attributes.rb
Last active February 24, 2024 14:11
Hardening SSH with 2fa
default['sshd']['sshd_config']['AuthenticationMethods'] = 'publickey,keyboard-interactive:pam'
default['sshd']['sshd_config']['ChallengeResponseAuthentication'] = 'yes'
default['sshd']['sshd_config']['PasswordAuthentication'] = 'no'
@lheckemann
lheckemann / 0-readme.md
Last active March 11, 2024 13:11
Expression for a buildEnv-based declarative user environment.

Expression for a buildEnv-based declarative user environment

This is one way of managing your user profile declaratively.

Alternatives include:

  • an attrset-based nix-env-based environment, installed using nix-env -ir rather than nix-env --set. LnL has an overlay which shows a way of doing this.
  • home-manager, which provides NixOS-like config for your $HOME

Note that this is incompatible with regular imperative use of nix-env, e.g. nix-env -iA nixpkgs.hello. It has the advantage of allowing the installation of multiple outputs of the same package much better than nix-env's builtin profile builder does.

@VladimirPal
VladimirPal / alembic_default_value.py
Last active April 1, 2024 19:14
default value alembic
# Boolean
op.add_column('projects', sa.Column('is_closed', sa.Boolean(), server_default=sa.schema.DefaultClause("0"), nullable=False))
# DateTime
op.add_column('projects_users', sa.Column('created_at', sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False))