Skip to content

Instantly share code, notes, and snippets.

@gildas
gildas / gpuA
Created July 7, 2022 13:24
git pull all branches from origin
#
# git pull all from origin
#
function gpuA {
local VERBOSE=${VERBOSE:-0}
while (( $# > 0 )); do
[[ $1 == --*=* ]] && set -- "${1%%=*}" "${1#*=}" "${@:2}"
case $1 in
--quiet)
@gildas
gildas / gpA
Created July 7, 2022 13:23
git push all remotes
#
# git push all and tags to origin or other repo
#
# This assumes git config push.default matching
function gpA {
local VERBOSE=${VERBOSE:-0}
while (( $# > 0 )); do
[[ $1 == --*=* ]] && set -- "${1%%=*}" "${1#*=}" "${@:2}"
case $1 in
@gildas
gildas / aws-auth.sh
Last active January 6, 2022 18:28
Starts a new AWS Session with an MFA Code
#!/usr/bin/env bash
function aws-auth() {
token_code=$1
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_SESSION_TOKEN_EXPIRATION
aws_identity=$(aws sts get-caller-identity --output json)
aws_account=$(echo "$aws_identity" | jq -r .Account)
aws_user=$(echo "$aws_identity" | jq -r .Arn | cut -d/ -f2)
aws_arn="arn:aws:iam::${aws_account}:mfa/${aws_user}"
creds=$(aws sts get-session-token --serial-number "$aws_arn" --token-code $token_code --duration-seconds 129600 --output json)
@gildas
gildas / new-awssession.ps1
Last active October 12, 2021 01:10
Starts a new AWS session with an MFA Code
function New-AWSSession {
<#
.SYNOPSIS
Authenticates with AWS using MFA
.DESCRIPTION
Authenticates the current IAM user with AWS via the assigned MFA device
.PARAMETER MFA
The MFA Code to authenticate with
.PARAMETER Profile
The AWS Profile to authenticate or "Default" if absent
package main
import (
"context"
"time"
"github.com/gildas/go-errors"
"github.com/gildas/go-logger"
)
# set history
set -g history-limit 50000
# Messages will be displayed for 4 seconds
set -g display-time 4000
set -g default-terminal screen-256color
# Disable auto-renaming of windows
set -g allow-rename off
@gildas
gildas / inheritance.go
Created January 18, 2021 02:06
How I solve "inheritance" in GO in regards to marshal/unmarshal
package main
import (
"encoding/json"
"fmt"
"reflect"
)
/******************** The TypeRegistry helper ******************/
/**** from github/gildas/go-core ****/
@gildas
gildas / sponge
Created November 26, 2020 03:18
a sponge replacement in case it is too difficult to install moreutils
#!/usr/bin/env bash
function main() {
local APPEND=0
while (( "$#" )); do
# Replace --parm=arg with --parm arg
[[ $1 == --*=* ]] && set -- "${1%%=*}" "${1#*=}" "${@:2}"
case $1 in
-a|--append)
@gildas
gildas / virmigrate.md
Last active August 23, 2024 09:56
Migration of Windows Virtual Machines from Hyper-V to OpenStack

Migration guide for Windows VMs from Hyper-V

First get the virtual disk (vhdx) from the Hyper-V platform.

Use a Linux machine with libvirt installed.

Do not forget to install the UEFI firmware:

sudo apt install ovmf
@gildas
gildas / logview
Last active July 17, 2020 09:44
view pm2 log files through the bunyan log viewer
#!/usr/bin/env bash
shopt -s extglob
set -o errtrace
#set -o errexit
set +o noclobber
# Defaults {{{
NOOP=
VERBOSE=${VERBOSE:0}