Skip to content

Instantly share code, notes, and snippets.

Avatar
😁
Happy!

Olivier Mengué dolmen

😁
Happy!
View GitHub Profile
@dolmen
dolmen / README.md
Last active March 9, 2023 17:47
go-redis v9 migration script
View README.md

Automated go-redis v8 -> v9 migration

About v8 -> v9

https://redis.com/blog/go-redis-official-redis-client/

Usage:

curl https://gist.githubusercontent.com/dolmen/9f5b4b1892588a5a8948a7c8e116660b/raw/dafeeb86c5c1c1fe80499b0c652f218c3c69aebd/migrate-go-redis-v9.sh | bash
@dolmen
dolmen / kh-to-hashcat.go
Last active January 5, 2023 10:40
Convert OpenSSH known_hosts for hashcat processing
View kh-to-hashcat.go
/*
kh-to-hashcat allows to convert an OpenSSH known_hosts hashed file to a
format that can be used with hashcat to recover hosts.
Note that as the know_hosts file usually contains multiple keys for each host
it is wise to filter the file to a single key type to filter redundant hashes.
Check this stat:
perl -nE '$c{$1}++ if /^\|1\|[^ ]+ ([^ ]+)/;END{say "$_: $c{$_}" for keys %c}' ~/.ssh/known_hosts
@dolmen
dolmen / go-text-template-hacks.md
Last active December 1, 2022 09:00
Go text/template hacks
View go-text-template-hacks.md

Go text/template hacks

Hacks below use goproc to experiment with Go templates from the command-line.

Convert bool to int

$ echo false | goproc -e '{{.}} => {{index "....\001\000" (len (print .))}}{{"\n"}}'
false => 0
$ echo true | goproc -e '{{.}} => {{index "....\001\000" (len (print .))}}{{"\n"}}'
@dolmen
dolmen / README.md
Created January 28, 2021 14:31
Get Go module+version string from a commit from GitHub
View README.md

github-go-version

Usage

github-go-version <owner>/<repo> <commit>
@dolmen
dolmen / git-go-aliases.sh
Last active October 19, 2020 12:29
Git aliases for Go developement #golang #git
View git-go-aliases.sh
# git go-version: shows the Go-modules versionning formatting of a Git commit
git config --global alias.go-version '!f(){ cd -- "${GIT_PREFIX:-.}"; TZ=UTC git log -1 '\''--date=format-local:%Y%m%d%H%M%S'\'' --abbrev=12 '\''--pretty=tformat:v0.0.0-%cd-%h'\'' "$@" ;};f'
# git go-get: shows the command to run on another Go project to upgrade this module
git config --global alias.go-get '!f(){ cd -- "${GIT_PREFIX:-.}"; TZ=UTC git log -1 '\''--date=format-local:%Y%m%d%H%M%S'\'' --abbrev=12 '\''--pretty=tformat:go get '\''"$(go list -m)"'\''@v0.0.0-%cd-%h'\'' "$@" ;};f'
# git go-shorlog: shows the 10 commits in Go-modules versionning style
git config --global alias.go-shortlog '!f(){ cd -- "${GIT_PREFIX:-.}"; TZ=UTC git log -10 '\''--date=format-local:%Y%m%d%H%M%S'\'' --abbrev=12 '\''--pretty=tformat:v0.0.0-%cd-%h %s'\'' "$@" ;};f'
@dolmen
dolmen / fix-url.go
Created June 12, 2020 17:12
Fix malformed URL query
View fix-url.go
// Fix (some kinds of) malformed URLs
package main
import (
"fmt"
"log"
"net/url"
)
@dolmen
dolmen / README.md
Last active July 13, 2022 05:52
go-bin-upgrade
View README.md

go-bin-upgrade

Rebuild the binaries you have built in Go module mode installed in $GOPATH/bin.

Usage: go-bin-upgrade [-n] [-v] bin1 [bin2]...

Examples:

  • go-bin-upgrade -n godoc
  • (cd ~/go/bin ; go-bin-upgrade * )
@dolmen
dolmen / export-400px.pl
Last active March 1, 2019 08:08
Nautilus script to convert a photo to reduced width of 400px
View export-400px.pl
#!/usr/bin/env perl
# Install as a Nautilus script:
# perl export-400px.pl --install
#
# Install dependencies:
# sudo aptitude install libimage-exiftool-perl libpath-tiny-perl imagemagick zenity
#
# Author: Olivier Mengué
# Created: Sun Feb 28 20:30:55 2016 +0100
@dolmen
dolmen / jsonroundtrip_test.go
Created February 19, 2019 13:19
Go: checkJSONRoundtrip
View jsonroundtrip_test.go
package main_test
import (
"encoding/json"
"reflect"
)
func checkJSONRoundtrip(t *testing.T, value interface{}, expectedJSON json.RawMessage) bool {
b, err := json.Marshal(value)
if err != nil {