Skip to content

Instantly share code, notes, and snippets.

javascript:(function(){const APP_ID='936619743392459';function csrf(){return document.cookie.match(/csrftoken=([^;]+)/)?.[1];}async function userId(username){const r=await fetch(`https://www.instagram.com/api/v1/users/web_profile_info/?username=${username}`,{headers:{%27x-ig-app-id%27:APP_ID,%27x-requested-with%27:%27XMLHttpRequest%27},credentials:%27include%27});const j=await r.json();return j?.data?.user?.id;}async function block(id){const r=await fetch(`https://www.instagram.com/api/v1/web/friendships/${id}/block/`,{method:%27POST%27,headers:{%27x-csrftoken%27:csrf(),%27x-ig-app-id%27:APP_ID,%27x-requested-with%27:%27XMLHttpRequest%27,%27content-type%27:%27application/x-www-form-urlencoded%27},credentials:%27include%27});return r.ok;}function getUsername(article){const links=[...article.querySelectorAll(%27a[href^="/"]%27)];for(const a of links){const m=a.getAttribute(%27href%27).match(/^\/([^\/]+)\/$/);if(!m)continue;const name=m[1];if([%27p%27,%27reel%27,%27reels%27,%27explore%27,%27stories%27,%27tv%27,%
@paolobrasolin
paolobrasolin / README.md
Last active December 17, 2024 10:32
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