Skip to content

Instantly share code, notes, and snippets.

View jobwat's full-sized avatar

Jo Boiteau jobwat

  • Servian
  • Sydney
View GitHub Profile
@jobwat
jobwat / .gitconfig
Created June 5, 2024 06:41
git alias to update current repository password in osxkeychain
# ...
[alias]
# ...
echo-remote-proto-and-host = "!f(){ REMOTE=origin; git remote -v | grep $REMOTE | head -n1 | sed -E \"s/^$REMOTE\\t+([a-z]+):\\/\\/([^\\/]+).*/protocol=\\1\\nhost=\\2/\";};f"
clear-credentials = "!f(){ git echo-remote-proto-and-host | git credential-osxkeychain erase ;};f"
get-credentials = "!f(){ git echo-remote-proto-and-host | git credential-osxkeychain get ;};f"
update-password = "!f(){ (git echo-remote-proto-and-host; git get-credentials) | sed \"s/password=.*/password=$1/\" | git credential-osxkeychain store ;};f"
# Usage:
#. Copy your new password in clipboard
@jobwat
jobwat / oneliner
Created February 14, 2024 00:06
list the remote branches with last commit authored by yourself
git branch -r | cut -d '/' -f 2- | grep -v '\->' | sort -u | while read branch; do [[ "$(git --no-pager log -n 1 --format='%ae' "origin/$branch" 2>/dev/null)" == "$(git config user.email)" ]] && echo $branch; done
@jobwat
jobwat / ssh-encrypt.sh
Created January 5, 2022 23:18
encrypt text with ssh key pair
## encrypt text with SSH key
# Notes:
# It's not as straightforward as someone would think!
# Need to convert the keys to an openssl known format (PEM) first.
# Also, SSH keys aren't meant to encrypt content larger than 200bytes
# Sources:
# https://superuser.com/questions/576506/how-to-use-ssh-rsa-public-key-to-encrypt-a-text
# https://serverfault.com/questions/706336/how-to-get-a-pem-file-from-ssh-key-pair
# https://superuser.com/questions/1679344/for-valid-pem-i-get-unable-to-load-private-key-by-openssh
@jobwat
jobwat / degressive_upkeep
Created December 10, 2021 01:58
Demo of grandfatherson Python library - Keeping 3 last days, 4 last weeks, and 3 months
import datetime
import random
from grandfatherson import to_keep, to_delete, MONDAY
import pytz
# Install notes:
# require grandfatherson & pytz - pip3 install grandfatherson pytz
utc=pytz.UTC
now = datetime.datetime.now().replace(tzinfo=utc) # ensure TZ aware
@jobwat
jobwat / commands
Created March 10, 2017 01:09
Docker nodes load balancer with nginx upstream
# Run 3 nodes
for i in 1 2 3; do
nod="n$i"
mkdir $nod
echo "$nod" >> $nod/index.html
docker run -d --name $nod -p 888${i}:80 -v `pwd`/${nod}:/usr/share/nginx/html:ro nginx
done
# Run a router proxy node
docker run --rm --name router -p 8888:80 -v `pwd`/default.conf:/etc/nginx/conf.d/default.conf nginx
@jobwat
jobwat / Dockerfile
Created March 9, 2017 04:34
Docker node crontab
FROM node:6
RUN apt-get update && apt-get -y install cron
RUN mkdir /app
ADD test.js /app
# Add crontab file in the cron directory
ADD crontab /etc/cron.d/hello-cron
@jobwat
jobwat / Dockerfile-app
Created January 24, 2017 05:29
Codeship demo case: write CI environment variables to file in image
FROM busybox
COPY data/BUILD_REV /
@jobwat
jobwat / curl_to_snappass.sh
Last active February 14, 2023 14:44
Send a file to snappass with curl via command line
cat my-file | curl https://snappass.nurun.com.au -s --data "password=$(cat - | perl -p -e 's/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg')&ttl=1+day" | grep 'password-link.*readonly' | sed -E 's/.*"(http[^"]*)".*/\1/'
@jobwat
jobwat / tmux.pres.remark.html
Created October 26, 2016 08:13
Quick Presentation tmux - remark
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<meta charset="utf-8">
<style>
@import url(https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz);
@import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic);
@import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic);
@jobwat
jobwat / guess_account.sh
Last active December 3, 2019 05:03
update .ssh/config with CloudFormation stack IPs
#!/bin/bash
aws_credentials_file=${HOME}/.aws/credentials
script_name=`basename $0`
error(){
echo "[${script_name}] Error: $@. Exiting."
exit 1
}