Skip to content

Instantly share code, notes, and snippets.

João Paulo Bochi jpbochi

Block or report user

Report or block jpbochi

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
@jpbochi
jpbochi / .bash_ps1
Created Aug 6, 2019
bash PROMPT_COMMAND + PS1 for git status
View .bash_ps1
#!/usr/bin/env bash
# copied from http://mediadoneright.com/content/ultimate-git-ps1-bash-prompt
# Customize BASH PS1 prompt to show current GIT repository and branch.
# by Mike Stewart - http://MediaDoneRight.com
# TODO: scope the following env vars to this file only. They can be seen with `declare -p`
# Reset
Color_Off="\[\033[0m\]" # Text Reset
@jpbochi
jpbochi / runcached.bash
Created Aug 2, 2019
Run speficied (presumably expensive) command with specified arguments and cache result. If cache is fresh enough, don't run command again but return cached output.
View runcached.bash
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o noglob
set -o pipefail
#
# Purpose: run speficied command with specified arguments and cache result. If cache is fresh enough, don't run command again but return cached output.
# Also cache exit status and stderr.
# License: GPLv3
@jpbochi
jpbochi / decrypt.sh
Last active Oct 10, 2018
bash SSH encrypt/decrypt/sign
View decrypt.sh
#!/usr/bin/env sh
set -eu
# some inspiration from https://raymii.org/s/tutorials/Sign_and_verify_text_files_to_public_keys_via_the_OpenSSL_Command_Line.html
MESSAGE=$1
ID_FILE=$(ssh -G git@github.com | grep identityfile | cut -d' ' -f2 | xargs -I % sh -c 'test -r % && echo % || true' | head)
echo >&2 '>>> decrypting with this identity file:' $ID_FILE
@jpbochi
jpbochi / init.lua
Created Oct 25, 2017
Hammerspoon config
View init.lua
hs.loadSpoon('ControlEscape'):start() -- Load Hammerspoon bits from https://github.com/jasonrudolph/ControlEscape.spoon
FRemap = require('foundation_remapping') -- https://github.com/hetima/hammerspoon-foundation_remapping
remapper = FRemap.new()
remapper:remap('§', '`')
remapper:register()
remapperDE = FRemap.new({vendorID=0x258a, productID=0x1006})
remapperDE:remap('lcmd', 'lalt')
@jpbochi
jpbochi / try-acquire-lock-s3.sh
Created Jul 25, 2017
bash script to lock/unlock resources by using an S3 bucket with file versioning
View try-acquire-lock-s3.sh
#!/usr/bin/env bash
set -eu
log () {
echo >&2 "[lock] $@"
}
putLock () {
aws s3api put-object --region $REGION --bucket $BUCKET --key $LOCK_KEY --output text --query 'VersionId'
}
View with-ssh-agent
#!/usr/bin/env sh
set -eu
eval $(ssh-agent -s)
KEYS=$(ls -p /var/ssh-keys/ | grep -v -e '/' -e config -e known_hosts -e '.pub$' -e authorized_keys)
echo "$KEYS" | xargs -I % ssh-add /var/ssh-keys/%
mkdir -p /root/.ssh
ssh-keyscan github.com >> /root/.ssh/known_hosts
echo 'host github.com' > /root/.ssh/config
View keybase.md

Keybase proof

I hereby claim:

  • I am jpbochi on github.
  • I am jpbochi (https://keybase.io/jpbochi) on keybase.
  • I have a public key whose fingerprint is 63F8 99D6 4386 AA0C AF2F FA06 46C0 764A 272F 53FC

To claim this, I am signing this object:

@jpbochi
jpbochi / best.sh
Last active Aug 16, 2016
bash file template
View best.sh
#!/usr/bin/env bash
# Bash3 Boilerplate. Copyright (c) 2014, kvz.io
# http://kvz.io/blog/2013/11/21/bash-best-practices/
# https://github.com/kvz/bash3boilerplate
set -o errexit
set -o pipefail
set -o nounset
# set -o xtrace
View iterm-open.sh
#!/bin/sh
# copied from https://gist.github.com/sos4nt/5245210
# In iTerm's Preferences > Profiles > Default > Advanced > Semantic History,
# choose "Run command..." and enter "/your/path/to/iterm_open_with \1 \2".
file "$1" | grep -q "text"
if [ $? -ne 0 ]; then
/usr/bin/open $1
else
View hats.js
//http://repl.it/IOn
function problem(colors, prisoners) {
function randomHat() {
return Math.floor(Math.random() * colors);
}
function randomHats() {
var hats = [];
for (var i = 0; i<prisoners; i++) {
You can’t perform that action at this time.