Skip to content

Instantly share code, notes, and snippets.

@assafmo
assafmo / uptime.sh
Last active August 26, 2020 09:01
Calculate validators uptime in the Secret Network
seq 2 250000 |
parallel --bar 'secretcli q block {} | jq -r ".block.last_commit.signatures[].validator_address | [{}-1,.] | @csv"'
@assafmo
assafmo / Caddyfile
Last active October 19, 2022 15:13
caddy conf for reverse proxy
banana.com
header {
Access-Control-Allow-Origin *
Access-Control-Allow-Methods *
Access-Control-Allow-Headers *
}
@corspreflight {
method OPTIONS
@assafmo
assafmo / main.js
Created May 26, 2020 13:42
AES-256-GCM in javascript
const forge = require("node-forge");
let key = forge.util.createBuffer(new Uint8Array(new Array(32).fill(0x7)).buffer);
let iv = forge.util.createBuffer(new Uint8Array(new Array(12).fill(0x0)).buffer);
const input = forge.util.createBuffer();
input.putString("banana");
var cipher = forge.cipher.createCipher("AES-GCM", key);
cipher.start({ iv: iv });
@assafmo
assafmo / fully static
Last active April 21, 2020 12:05
Golang build flags
go build -ldflags '-linkmode external -extldflags "-static"'
@assafmo
assafmo / script-name.service
Created March 23, 2020 12:00
Create a startup script with systemd (/etc/rc.local replacement)
# Put in /etc/systemd/system/script-name.service
# Then run `sudo systemctl enable script-name`
[Unit]
Description=bla bla
[Service]
Type=oneshot
ExecStart=/bin/mount -o remount,exec /dev
RemainAfterExit=true
@assafmo
assafmo / purge_docker_data.sh
Last active March 18, 2020 12:50
Purge docker containers and images
#!/bin/bash
docker ps -a |
tail -n +2 |
awk '{print $1}' |
xargs -r docker rm -f
docker images |
tail -n +2 |
awk '{print $3}' |
xargs -r docker rmi -f
@assafmo
assafmo / chart_community_pool.sh
Last active April 14, 2020 08:47
Chart community pool balance over time on the Enigma Blockchain
#!/bin/bash
seq 1000 1000 $(enigmacli status | jq -r .sync_info.latest_block_height) |
parallel --bar -P 1 --lb "printf '{} ' ; enigmacli q distribution community-pool --height {} | jq -r '.[].amount'" |
awk 'BEGIN{print "block_height,community_pool_scrt"; print "0,0"} {print $1 "," $2/10^6}'
@assafmo
assafmo / export_peers.sh
Last active September 23, 2020 21:29
Export a list of peers from your Enigma blockchain node
#!/bin/bash
curl -s http://bootstrap.mainnet.enigma.co:26657/net_info |
jq -cr '.result.peers[] | [.node_info.id,.remote_ip,.node_info.listen_addr] | @csv' |
tr -d \" |
tr , @ |
perl -pe 's#\@tcp://.+?:#:#g' |
sort > /tmp/peers.txt
echo "# Generated at $(date -u --rfc-3339=seconds) by https://gist.github.com/assafmo/a39fdb535f74ce2d6493a1a3f695e4ca" > /home/ubuntu/peers/peers.txt
@assafmo
assafmo / jq.validate.sh
Created November 24, 2019 09:42
jq process only valid JSONs
cat some.log | jq -R 'fromjson? | .date'
@assafmo
assafmo / setup.sh
Last active March 17, 2020 08:37
Setup a new ubuntu machine for performance
#!/bin/bash
set -e
##
# CPU scaling_governor=performance
##
printf 'Setting scaling_governor to performance... '
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor > /dev/null