Skip to content

Instantly share code, notes, and snippets.

View benpitman's full-sized avatar

Ben Pitman benpitman

  • Manchester, England
View GitHub Profile
@benpitman
benpitman / install_tmux.sh
Last active January 6, 2020 11:04
Install latest version of tmux on CentOS 7
#!/usr/bin/env bash
declare -g -- _sudo=
declare -ag -- _foldersToRemove=()
declare -ag -- _filesToRemove=()
trap cleanup SIGINT SIGTERM
die ()
{
@benpitman
benpitman / levenshtein.sh
Last active August 14, 2022 21:01
Bash function to calculate the levenshtein distance between two strings
#!/usr/bin/env bash
levenshtein ()
{
local -r -- target=$1
local -r -- given=$2
local -r -- targetLength=${#target}
local -r -- givenLength=${#given}
local -- alt
local -- cost
@benpitman
benpitman / .bashrc
Created December 7, 2018 12:20
My personalised bashrc
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
prompt_command() {
local RETNUM=$?
@benpitman
benpitman / Identicon.sh
Last active June 23, 2020 15:45
Randomly generates an identicon. Parameters are width, height and a boolean for symmetry.
#!/usr/bin/env bash
bool='^[Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee]$'
digit='^[0-9]+$'
width=5
symmetrical=false
if [[ -n "$1" ]]; then
if [[ "$1" =~ $digit ]]; then
width=$(( $1 < 1 ? 1 : $1 ))
@benpitman
benpitman / AbstractRepository.pm6
Last active March 6, 2024 02:19
Perl6 DBIish wrapper for SQLite queries
#!/usr/bin/perl6
use v6;
use DBIish;
need Service::Service;
role AbstractRepository
{
has $.table is rw;
@benpitman
benpitman / binary_clock.sh
Created June 12, 2018 06:44
A binary clock I made in Bash v4+ that runs in the background, updates every minute, and prints to the top right of the terminal.
#!/bin/bash
tick() {
local \
ampm \
calibrate=true \
D2B=({0..1}{0..1}{0..1}{0..1}{0..1}{0..1}) \
hour \
in_cli \
minute \