Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
&> /dev/null

Gibran Malheiros gibatronic

💭
&> /dev/null
View GitHub Profile
@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
View .editorconfig
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
View slide.sh
#!/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/
@gibatronic
gibatronic / cancellable-promises
Created April 17, 2020 19:18
Cancellable Promises
View cancellable-promises
#!/usr/bin/env node
class CancelError extends Error {
constructor(message) {
super(message)
this.name = 'CancelError'
}
}
function random(minimum, maximum) {
@gibatronic
gibatronic / scale-duration
Created January 21, 2019 12:43
ffmpeg: scale up or down the duration of the given video
View scale-duration
#!/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
View redirect-port-80-to-8080
#!/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 / README.md
Created October 26, 2018 12:58
Proper job control in Bash scripts
View README.md

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.
View delete-quicklook-cache
#!/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=$?
View webm2mp4
#!/usr/bin/env bash
#
# Convert any webm video file inside the Downloads folder to mp4
#
# Usage:
# ./webm2mp4
main() {
local videos=$(find ~/Downloads -name '*.webm')
@gibatronic
gibatronic / commit-msg
Last active August 21, 2018 13:12
Prepend the branch name to the commit message
View commit-msg
#!/usr/bin/env bash
main() {
local commit_message_file=$1
local branch_name=$(__git_ps1 '%s' | cut -d '|' -f 1)
local commit_message=$(cat "$commit_message_file")
# do nothing if the commit_message already begins with the branch_name
if [[ "$commit_message" == "$branch_name"* ]]; then
@gibatronic
gibatronic / README.md
Last active June 9, 2023 07:14
Tab completion for the npx command
View README.md

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