Skip to content

Instantly share code, notes, and snippets.

View gibatronic's full-sized avatar
💭
&> /dev/null

Gibran Malheiros gibatronic

💭
&> /dev/null
View GitHub Profile
@gibatronic
gibatronic / README.md
Last active January 25, 2024 21:46
Tab completion for the npx command

complete_npx

Bash tab completion for the npx command

Usage

Save complete_npx in your home folder and then source it on your .bash_profile with:

. ~/complete_npx.sh
@gibatronic
gibatronic / README.md
Last active May 5, 2023 12:14
Node crypto.pbkdf2 example to securely store and check passwords.

password.js

Tiny Node.js module to securely hash and compare passwords using pbkdf2 with per password random salt.

Usage

To hash a password:

var password = require('./password');
@gibatronic
gibatronic / .editorconfig
Last active April 14, 2023 17:08
Slowly spin a bipolar stepper motor, with gentle power up and down for smooth steps
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
insert_final_newline = true
[{Makefile,*.sh}]
indent_style = tab
@gibatronic
gibatronic / slide.sh
Created January 11, 2023 23:21
Slide an image to the left using ffmpeg
#!/usr/bin/env bash
#
# Slide an image to the left using ffmpeg
#
# Usage:
# ./slide photo_input.jpg video_output.mp4
#
# See:
# https://ffmpeg.org/ffmpeg-filters.html#overlay-1
# https://easings.net/
#!/usr/bin/env bash
#
# Make your server get traffic from port 80 without having to run it with sudo privilege.
# Based on: Running Jenkins on Port 80 or 443 using iptables
# https://wiki.jenkins.io/display/JENKINS/Running+Jenkins+on+Port+80+or+443+using+iptables
# allow traffic on ports 80 and 8080
sudo iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT
sudo iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT
@gibatronic
gibatronic / cancellable-promises
Created April 17, 2020 19:18
Cancellable Promises
#!/usr/bin/env node
class CancelError extends Error {
constructor(message) {
super(message)
this.name = 'CancelError'
}
}
function random(minimum, maximum) {
@gibatronic
gibatronic / workit.bash
Last active June 24, 2019 09:10
Automatically run workon when entering a directory
function check_for_virtual_env {
[ -d .git ] || git rev-parse --git-dir &> /dev/null
if [ $? == 0 ]; then
local ENV_NAME=`basename \`pwd\``
if [ "${VIRTUAL_ENV##*/}" != $ENV_NAME ] && [ -e $WORKON_HOME/$ENV_NAME/bin/activate ]; then
workon $ENV_NAME && export CD_VIRTUAL_ENV=$ENV_NAME
fi
elif [ $CD_VIRTUAL_ENV ]; then
@gibatronic
gibatronic / scale-duration
Created January 21, 2019 12:43
ffmpeg: scale up or down the duration of the given video
#!/usr/bin/env bash
#
# Scale up or down the duration of the given video
# The final video will be in the mp4 format
#
# Usage:
# scale-duration <video-path> <desired-duration>
#
# Options:
# video-path The video to scale
@gibatronic
gibatronic / README.md
Created October 26, 2018 12:58
Proper job control in Bash scripts

Proper job control in Bash scripts

Simple example of how to properly launch background jobs and then gracefully terminate them.

Gotchas

  1. We could trap only the EXIT signal, but then after killing workers we get an unwanted "Terminated" message.
  2. In worker scripts, we must call exit when cleaning, to break out of the infinite loop
  3. After killing a worker, we still have to wait for them to gracefully terminate.
#!/usr/bin/env bash
#
# Reset Quick Look and all of its cache
#
# Usage:
# ./delete-quicklook-cache
main() {
qlmanage -r cache > /dev/null
local exit_code=$?