Skip to content

Instantly share code, notes, and snippets.

@renier
renier / gist:84643b29cd9f4e0308bca4cc3c1ea5ab
Created July 8, 2024 23:51
Building ffmpeg from source and installing into the homebrew prefix
./configure --prefix=/opt/homebrew/Cellar/ffmpeg/7.0.1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags='-Wl,-ld_classic' --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libharfbuzz --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox --enable-neon --enable-l
@renier
renier / goexplain.sh
Last active September 23, 2024 20:30
Like go mod why but for dependencies in go.sum and not in go.mod - will also work around direct dependencies listed as indirect which can happen with the use of replace directives downstream. Understands module argument with and without the version.
#!/bin/bash
# Like go mod why but for dependencies in go.sum and not in go.mod - will also
# work around direct dependencies in the graph listed as indirect in go.mod
# which can happen with the use of replace directives downstream. Understands
# module argument with and without the version.
#
# usage: ./goexplain.sh example.com/path/module
# usage: ./goexplain.sh example.com/path/module@v1.0.0
bold=$(tput bold)
@renier
renier / multi_page_image.md
Last active June 2, 2020 18:35
Breaking an image into multiple pages

I sometimes use Awesome Screenshot Plus to print a web page. It comes in handy as not all web pages are optimized for printing. This can result in a very long image if the content is multiple pages long, which is also not great for printint it out, since everything will come out as a single page due to scaling (on OSX).

There are probably other ways to solve this, but I've found ImageMagick to work very well in these cases. You'll need to know how many pages you need. For that, you'll need to know the dimensions of the source image. You can also gather this info with ImageMagick.

$ convert doc.jpg -print "Size: %wx%h\n" /dev/null

Now that you know the pixel width and height, use some math to figure out how many pages you'll need. The following is an example for letter size pages (8.5 x 11 inches):

@renier
renier / generateRandomNumber.js
Last active November 22, 2019 19:37
Generate random number with bit length specified in Node.js
const crypto = require('crypto');
// Generates a random number of the bit length specified in base 16 format (hexadecimal).
// bitLength should be a multiple of 8.
function generateRandomNumber(bitLength) {
return crypto.randomBytes(bitLength / 8).toString('hex');
}
// > generateRandomNumber(64)
// '9c493dcad246f3c1'
@renier
renier / search_and_cmd.sh
Created August 16, 2019 02:16
Execute commands on all found files even if they have spaces and quotes in their names
while read f; do
$(cmd) -- "${f}"
done < <(find . -name "*.ext" -print0 | xargs -0 -n1 grep -Hsl "foobar")
@renier
renier / fast_harden_ubuntu.sh
Last active February 24, 2019 05:35
Fast Harden Ubuntu
#!/bin/bash
apt-get install ufw -y
apt-get install denyhosts -y
# Configure firewall
ufw default deny incoming
ufw default allow outgoing
ufw allow ssh
ufw --force enable
@renier
renier / gowo.sh
Last active March 16, 2018 17:39
gowo - Go workspace switcher
# Usage: gowo my_go_workspace
# Will set GOPATH and update PATH with the bin dir. Will remove previous GOPATH bin dir from the PATH.
# Opinionated about the root dir where Go workspaces go. Change if you want.
# Put this in your ~/.bash_profile
export GOPATH=$HOME/Projects/go
export PATH=$PATH:$GOPATH/bin
function gowo() {
@renier
renier / gen_cert.sh
Created October 30, 2016 08:06
Generate an SSL certificate
#!/bin/bash
DOMAIN=$(hostname -f)
export PASSPHRASE=$(head -c 500 /dev/urandom | tr -dc a-z0-9A-Z | head -c 128; echo)
subj="
C=$1
ST=$2
O=$3
localityName=$4
commonName=$DOMAIN
organizationalUnitName=$5
@renier
renier / super_harden_ubuntu.sh
Last active February 10, 2019 02:05
Super Harden Ubuntu
#!/bin/bash
# https://developer.ibm.com/answers/questions/462237/error-groot-must-be-grub-root-device-on-ubuntu/
sed -i -e 's/LABEL=cloudimg-rootfs/(hd0)/' /boot/grub/menu.lst
apt-get update > /dev/null
apt-get install unattended-upgrades -y
timeout 20m unattended-upgrade
apt-get autoremove -y
apt-get autoclean -y
@renier
renier / harden_ubuntu.sh
Last active September 8, 2017 05:56
Harden Ubuntu
#!/bin/bash
apt-get update
apt-get upgrade -y
apt-get autoremove -y
apt-get autoclean -y
apt-get install ufw -y
apt-get install denyhosts -y
# Configure firewall