Skip to content

Instantly share code, notes, and snippets.

View Da-Juan's full-sized avatar
🛠️

Nicolas Rouanet Da-Juan

🛠️
View GitHub Profile
@Da-Juan
Da-Juan / get_ips_from_urls.sh
Created November 4, 2016 14:12
Get IPs from a file containing URLs
#!/bin/bash
for i in $(sed -r 's@^http[s]?://([[:alnum:].]+)[/]?$@\1@' $1); do
echo "=== $i ==="
echo $i | egrep -q "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"
if [ $? -eq 0 ]; then
echo $i
else
host -t A $i | grep address | awk '{print $4}'| sort
fi
done
@Da-Juan
Da-Juan / youtube-dl_cheat_sheet.md
Last active March 30, 2018 08:24
youtube-dl cheat sheet
  • List Formats:
youtube-dl --list-formats <URL>
  • Download video with english subtitles, and embed them, using best formats available
youtube-dl --no-playlist --format best --sub-lang en --sub-format best --write-sub --embed-subs <URL>
@Da-Juan
Da-Juan / booklet.sh
Created March 30, 2018 08:29
Order page numbers to print in booklet
#!/bin/bash
n=$1
j=0
pages=""
for i in $(seq 1 $(( n / 2))); do
if [ $((i%2)) -ne 0 ]; then
if [[ $pages != '' ]]; then
pages=$pages','
fi
pages=$pages$(( n - j ))','$i
@Da-Juan
Da-Juan / bash_docker.sh
Created June 4, 2018 11:20
Run bash in background in a Docker image
docker run --name debian9 --hostname debian9 -d debian:9 /bin/bash -c "trap : TERM INT; sleep infinity & wait"
@Da-Juan
Da-Juan / rm_exclusion.sh
Created June 6, 2018 08:39
Remove all files except some
#!/bin/bash
# Enable Extended Globbing
shopt -s extglob
# Simple version
rm !(a|b|c)
# Scriptable version
function join_by {

ffmpeg cheat sheet

Re-encode mkv to h264 keeping audio and subtitles tracks

ffmpeg -i input.mkv -map 0:1 -map 0:a -map 0:s -c:a copy -c:s copy -c:v libx264 output.mkv

Explanations:

  • -map 0:1 select first video stream
@Da-Juan
Da-Juan / percentage_output.py
Created November 7, 2018 14:53
Write growing percentage on standard output
#!/usr/bin/env python3
"""Percentage output."""
count = 0
items_nb = 500000
while True:
# You can replace .0f by .2f to output decimals
print(f'{count * 100 / items_nb:.0f}%', end='\r')
count += 1
@Da-Juan
Da-Juan / progressbar.py
Last active August 12, 2019 16:52
Simple progress bar in Python 3.6
#!/usr/bin/env python3
"""Display a progressbar."""
import sys
import time
def progressbar(
progress: int, total: int,
percentage: bool = True, bar_width: int = 40,
todo: str = ' ', done: str = '=',
@Da-Juan
Da-Juan / secret_santa.py
Last active December 5, 2018 12:30
Radomize secret santa pairings
#!/usr/bin/python3
import random
people = [
"Foo",
"Bar",
"Baz",
"Qux",
"Quux",
"Corge",
@Da-Juan
Da-Juan / opnsense_add_OCSP_stapling.md
Last active February 21, 2024 15:00
opnsense/haproxy: add OCSP stapling support

Here is a work around to automate OCSP stapling on Opnsense with HAproxy plugin.

Hope it helps :)

I created a script based on acme.sh's haproxy deploy hook.

As /tmp is emptied on reboot you need to regenerate ocsp files on startup so I put the script as a startup script: /usr/local/etc/rc.syshook.d/start/99-ocsp (symoblic links in rc.syshook.d don't work).

#!/bin/sh