Skip to content

Instantly share code, notes, and snippets.

View rlegene's full-sized avatar

Robert Martin-Legene rlegene

View GitHub Profile
@rlegene
rlegene / gethconsole2json
Last active August 24, 2022 17:40
geth attach doesn't give proper JSON
#!/bin/bash
# geth --exec admin.nodeInfo attach | gethconsole2json
sed -E '
s/^( *)([A-Za-z0-9_]+):/\1"\2":/ ;
/: *(\{|true,?|false,?|[0-9]+,?|".*",?)$/{p;d} ;
s/^([^:]+: *)(.+),$/\1"\2",/ ;
s/^([^:]+: *)(.+[^,])$/\1"\2"/
'
@rlegene
rlegene / init-with-docker-secrets.sh
Created July 22, 2021 20:38
using docker secrets for init scripts
#!/bin/bash
function get_secret
{
local variablename="$1"
local filename="/run/secrets/$variablename"
local default="$2"
if [ -r "$filename" ]
# If the file with the secret exists, then read it unconditionally
then
eval "$variablename=\"$(< "$filename")\""
@rlegene
rlegene / nicetime.sh
Last active November 27, 2020 21:35
Print current `date` in YYYYMMDD-HHMMSS format.
#!/bin/bash
# (c)20201127robert@martin-legene.dk
# License: CC0
# $SECONDS is a bash feature. See manual for info.
SECONDS=$(date +%s)
nicetime()
{
# Bash's built-in printf accepts this kind of time formatting
@rlegene
rlegene / not
Last active November 27, 2020 21:34
Shell script returns the opposite success value of a command
#!/bin/bash
# (c)20201113robert@martin-legene.dk
# License: CC0
# Executes a command and returns the opposite success value
# if not false ; then echo true ; fi
# (prints true)
"$@" && exit 1
exit 0
@rlegene
rlegene / yaml-mangle.pl
Last active January 24, 2020 05:51
Basic YAML CLI node editing
#!/usr/bin/perl -w
# 20200124 Robert Martin-Legene
# Allows you to add some fields in YAML.
# I stopped developing this when it met my needs.
# Reads STDIN, writes STDOUT.
# Only does the first document.
# YAML::Tiny doesn't guarantee the order of the elements read.
use warnings;
use strict;
@rlegene
rlegene / test-account.js
Created October 29, 2019 21:59
setting up and using the same test account in web3js
#!/usr/bin/node
"use strict"
const fs = require( 'fs' );
const Web3 = require( 'web3' );
var web3 = new Web3;
function initaccount( filename )
{
@rlegene
rlegene / sleep.sh
Created October 16, 2019 07:00
Calling sleep many times in bash takes one process per time you sleep. Not anymore!
#!/bin/bash
# 20191016 Robert Martin-Legene
# CC0
# Make us a directory just for this pipe
sleepdir=$( mktemp -d )
# Remember to clean up when we're done
tailpid=
trap 'test -n "${tailpid}" && kill ${tailpid} ; rm -rf ${sleepdir}' EXIT
@rlegene
rlegene / mousemove.sh
Created June 26, 2018 13:01
Move your X mouse cursor from your keyboard.
#!/bin/bash
# 20180614 Robert Martin-Legene, CC-BY-SA
# Tired of moving your hand to your mouse all the time?
# This script helps you move the mouse cursor just a tiny bit,
# and then raises the window it ends up over.
# Depends on: xdotool, xbindkeys
## Add the next 4 definitions to ~/.xbindkeys and make sure
## your window manager doesn't interfere with your chosen shortcut
@rlegene
rlegene / tldcheck.sh
Last active June 13, 2018 21:32
Script to check all (cc?)TLD name servers.
#!/bin/bash
# 20180613 Robert Martin-Legene CC-BY-SA
# How many parallel checks?
maxproc=50
# mx lookup domain, used for estimating if a server is recursive
mxfqdn=eff.org
# This works on Linux
@rlegene
rlegene / keybase.md
Last active January 25, 2018 16:17
Keybase proof

Keybase proof

I hereby claim:

  • I am rlegene on github.
  • I am rlegene (https://keybase.io/rlegene) on keybase.
  • I have a public key ASBKg41xNUl9HBSABXVDiPBLNZmlX3DWu8BNdMDQNr6Trwo

To claim this, I am signing this object: