Skip to content

Instantly share code, notes, and snippets.

Gibran Malheiros gibatronic

Block or report user

Report or block gibatronic

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@gibatronic
gibatronic / scale-duration
Created Jan 21, 2019
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 Oct 26, 2018
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 Aug 21, 2018
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
Created Feb 18, 2018
Tab completion for the npx command
View README.md

complete_npx

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
View find-leading-zero-hash.js
const crypto = require('crypto');
let hash;
let index = 0;
function check() {
const data = hash.read().toString('hex');
hash.removeListener('readable', check);
@gibatronic
gibatronic / README.md
Last active Mar 11, 2017
gibon require webpack issue
View README.md

Steps to reproduce:

# install webpack
npm i -g webpack

# bundle
webpack router.js bundle.js

# execute
@gibatronic
gibatronic / leave
Created Apr 11, 2016
Stupid tool to calculate what time I should leave given the time I arrived at work to complete 8.5h with 1h of lunch.
View leave
#!/usr/bin/env node --harmony
const output = function(...data) {
process.stdout.write(data.join(''));
};
const main = function(hour, minute) {
hour = +hour;
minute = (minute / 60) || 0;
You can’t perform that action at this time.