Skip to content

Instantly share code, notes, and snippets.

@benjaminblack
benjaminblack / installing-debian-with-an-encrypted-boot-partition
Last active March 5, 2021 15:17
Installing Debian with an encrypted boot partition
Create "rescue" partition, do minimal installation, boot (replace ? with root partition device):
[Grub console:]
> set root=(hd0,gptX)
> linux /vmlinuz root=/dev/?
> initrd /initrd.img
> boot
Bring it up to date and install cryptsetup.
@benjaminblack
benjaminblack / counting-unique-404s-in-apache-log-files
Last active September 22, 2015 14:16
Counting unique 404s in Apache log files
Tl;dr:
gunzip --to-stdout logfile-*.gz | grep " 404 " | cut -d " " -f 7 | sort | uniq -c | sort --numeric-sort --reverse > unique-404s.txt
Starting with a bunch of gzipped log files, like "logfile-*.gz".
First, uncompress to stdout:
gunzip --to-stdout logfile-*.gz
@benjaminblack
benjaminblack / recursively-copy-a-remote-directory-with-rsync
Last active September 22, 2015 14:16
Recursively copy a remote directory with rsync
rsync --checksum --human-readable --archive --verbose --compress --partial --progress --rsh=ssh <host>:<remote-path> <local-path>
* Note: if <path> ends with /, the specified directory is not included in the copy, just its contents (recursively). I.e., to copy a remote "folder" to a local "folder", without copying the folder itself, include a trailing "/" in the remote path.
Options:
--checksum: skip based on checksum, not mod-time & size
--human-readable: output numbers in a human-readable format
--archive: archive mode; same as -rlptgoD (no -H)
-r, --recursive: recurse into directories
-l, --links: copy symlinks as symlinks
@benjaminblack
benjaminblack / apache-ssi-server-side-includes-matching-variables-with-regular-expressions-using-the-v-function
Last active September 24, 2015 18:01
Apache SSI (Server Side Includes) matching variables with regular expressions using the 'v' function
<!--#if expr="v('REQUEST_URI') =~ m#^/contact#" -->
<!--#set var="pathclass" value="contact" -->
<!--#elif expr="v('REQUEST_URI') =~ m#^/work#" -->
<!--#set var="pathclass" value="work" -->
<!--#elif expr="v('REQUEST_URI') =~ m#^/$#" -->
<!--#set var="pathclass" value="about" -->
<!--#endif -->
<html lang="en-US" class="<!--#echo var="pathclass" -->">
@benjaminblack
benjaminblack / gist:72b30baa0e5dbc73914f
Created October 10, 2015 23:42 — forked from saetia/gist:1623487
Clean Install – OS X 10.11 El Capitan

OS X Preferences


most of these require logout/restart to take effect

# Enable character repeat on keydown
defaults write -g ApplePressAndHoldEnabled -bool false

# Set a shorter Delay until key repeat
@benjaminblack
benjaminblack / bash-functions-implementing-working-directory-history
Last active November 26, 2015 02:31
Bash functions implementing working directory history
#!/bin/bash
export WDHIST=( $(pwd) )
function cd {
builtin cd $*
if [ $? -eq 0 ]; then
WDHIST[${#WDHIST[*]}]=$(pwd)
fi
}
@benjaminblack
benjaminblack / os-x-add-trusted-certificate-to-system-chain
Created April 4, 2016 01:59
OS X: Add a trusted certificate to the system chain
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain site.crt
@benjaminblack
benjaminblack / high-resolution-timers-in-node.md
Last active November 16, 2017 23:01
High-resolution timers in Node
function longrunning() {
    const timestamp = process.hrtime(); // returns high-resolution array pair: [seconds, nanoseconds]
    // ...
    // do something
    // ...
    const elapsed = (([sec, ns] = process.hrtime(timestamp)) => ((sec + (ns / 1e9)) * 1e3))(); // converts [seconds, nanoseconds] into milliseconds
}
@benjaminblack
benjaminblack / lets-encrypt-certbot-acme-client-manual-dns-challenge.md
Last active August 6, 2023 23:28
Let's Encrypt certbot ACME client manual DNS challenge

Let's Encrypt certbot ACME client manual DNS challenge

certbot certonly [--dry-run] --manual --preferred-challenges dns-01 \
--domain example.com --domain www.example.com [...]

For each host passed via --domain, Let's Encrypt will prompt the user to create an _acme-challenge TXT record (_acme-challenge.example.com, _acme-challenge.www.example.com, etc.) with a specific value.

@benjaminblack
benjaminblack / debian-update-to-bpo-kernel-during-install.md
Last active December 24, 2016 02:41
Debian: Update to BPO kernel during install

It is possible to update the kernel to the most recent backports version during installation.

Proceed with an expert installation all the way through configuring the package manager, and ensure the Backports option is selected.

Switch to the console (Alt-F2), and chroot into the installation:

mount --rbind /dev/ /target/dev/
mount --rbind /run/ /target/run/
mount --rbind /sys/ /target/sys/