Skip to content

Instantly share code, notes, and snippets.

@paolobrasolin
paolobrasolin / README.md
Last active May 12, 2024 13:17
A::B prompting challenge
@paolobrasolin
paolobrasolin / README.md
Last active February 2, 2022 12:15
Scripts to embed LaTeX in Markdown documents

Hi! This is a pair of scripts to easily embed LaTeX figures in Markdown documents.

Before using them, please

  1. modify TEX_DIR to be the folder where you want to keep the LaTeX stuff (./attachments/diagrams will be fine if you're using Obsidian);
  2. modify PREAMBLE and POSTAMBLE the LaTeX code to sandwitch the code of your figures before compilation;
  3. carefully read the scripts, as you're running Bash given to you by a stranger.

Then, you can use them like this:

@paolobrasolin
paolobrasolin / ssh-tunne-to-pg-socket.sh
Created October 15, 2021 15:41
Open an SSH tunnel to a PG socket
#!/usr/bin/env bash
DB=${1:-my-host}
PORT=${2:-10864}
echo "Opened tunnel on port $PORT to $DB through websocket..."
ssh -N -L localhost:$PORT:/var/run/postgresql/.s.PGSQL.5432 $DB
echo "Closed!"
@paolobrasolin
paolobrasolin / git_redemption.sh
Created October 15, 2021 15:40
Replace user/email in git history
#!/usr/bin/env bash
git filter-branch --env-filter '
OLD_MAIL="paolo.brasolin@email.com"
NEW_NAME="Paolo Brasolin"
NEW_MAIL="paolo.brasolin@gmail.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_MAIL" ]
then
@paolobrasolin
paolobrasolin / README.md
Last active October 15, 2021 15:19
Timetrap formatter

Place the formatter in ~/.timetrap/formatters/det.rb and then run

t week -f det

to obtain

2019-11-18 10:23 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■⠅⠅⠅⠅⠅⠅⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂
@paolobrasolin
paolobrasolin / rndch.sh
Created April 6, 2018 17:45
POSIX random string
rndch () { cat /dev/urandom | LC_ALL=C tr -dc '[:graph:]' | head -c $1; };
def self.humanize_bytes(size)
%w[b Kb Mb Gb Tb Pb Eb Zb Yb].reduce(size) do |magnitude, unit|
break "#{magnitude}#{unit}" if magnitude < 1024
magnitude / 1024
end
end
def self.humanize_bytes(size)
return "#{size}b" if size < 1024
return "#{size}Kb" if (size /= 1024) < 1024
@paolobrasolin
paolobrasolin / !git_locstat.md
Last active March 17, 2018 15:47
git locstat

git locstat

The alias computes per-user lines of code.

Parameters are passed on to git ls-files: the main intended use is tallying a certain section of a project.

E.g. to examine the backend of a Rails' project you can run

git locstat :**.rb :^lib