Skip to content

Instantly share code, notes, and snippets.

View iAnatoly's full-sized avatar

Anatoly Ivanov iAnatoly

View GitHub Profile
@iAnatoly
iAnatoly / base64
Created August 4, 2016 17:55
One-liners encoding and decoding Base64 in powershell
[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("SecretMessage"))
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String("U2VjcmV0TWVzc2FnZQ=="))
@iAnatoly
iAnatoly / softnetstat.py
Created March 24, 2021 18:01
Ad-hoc monitoring for time_squeeze changes in /proc/net/softnet_stat
#!/usr/bin/env python3
#
# Ad-hoc monitoring for time_squeeze changes in /proc/net/softnet_stat .
#
# usage: ./softnetstat.py <refresh_interval_seconds>
#
# see https://blog.packagecloud.io/eng/2016/06/22/monitoring-tuning-linux-networking-stack-receiving-data/
#
from time import sleep
from datetime import datetime
@iAnatoly
iAnatoly / json-to-sqlite.md
Last active December 24, 2022 19:06
Convert json to a sqlite database for querying

Sometimes, you need to quickly dump a json file into sqlite, just to run some queries on it. This is a two-step process:

1. convert json to csv

cat file.json | jq -r '.data | map([.field1, .field2, .field3] | @csv)| join("\n")' > file.csv

1a. add headers line into your csv file, i.e.

@iAnatoly
iAnatoly / TELEGRAM.md
Last active May 24, 2022 01:19
send alert messages to a telegram channel.
  1. create bot by messaging @botfather (/newbot)
  2. save a token in env var: export token="yourtokenfrombotfather". If you need to re-issue a token, use /revoke command to botfather.
  3. add your bot to a channel you intend for alerts
  4. Send some message into that channel using telegram client. A simple "test" will do.
  5. get chat id: curl https://api.telegram.org/bot${token}/getUpdates | grep test
  6. send a test message: curl https://api.telegram.org/bot${token}/sendMessage --data '{"chat_id":${chat_id},"text": "message"}' -H "Content-type: application/json"
  7. codify the above experience.
#!/bin/bash
set -eu -o pipefail
  1. Create a file with json request, for example:
$ cat > TTS.json <<END
{
  "audioConfig": {
    "audioEncoding": "LINEAR16",
    "pitch": 0,
    "speakingRate": 1
 },
@iAnatoly
iAnatoly / sip_ping.py
Last active May 13, 2022 15:34
SIP ping
#!/usr/bin/env python3
import socket
import time
userid = "trivial_sip_pinger"
domain = "<sip server to test>"
port = 5060
timeout_ms = 1000
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@iAnatoly
iAnatoly / change_luks.md
Last active May 12, 2022 21:08
Change Luks password

First, find out which is the encrypted LVM partition

cat /etc/crypttab

To add a new password, use luksAddKey:

sudo cryptsetup luksAddKey /dev/sda3

To remove an existing password, use luksRemoveKey:

@iAnatoly
iAnatoly / generate-random.sh
Last active May 6, 2022 18:15
Generate given number of random files
#!/bin/bash
TARGET_FILE_NUM=$1
CURRENT_FILE_NUM=`ls -l | wc -l`
FILES_TO_GENERATE=$((TARGET_FILE_NUM - CURRENT_FILE_NUM))
if [[ $FILES_TO_GENERATE -lt 0 ]]; then
echo "We already have $CURRENT_FILE_NUM files, no need to generate more"
exit
fi
@iAnatoly
iAnatoly / generate_self_signed.sh
Created May 4, 2022 01:54
openssl self-signed cert one line
#!/bin/bash
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365 -nodes
@iAnatoly
iAnatoly / gist:77fcafc884a80faadf015edf28a9c938
Created April 27, 2022 21:47
Emulating packetloss and latency
https://stackoverflow.com/questions/614795/simulate-delayed-and-dropped-packets-on-linux
https://wiki.linuxfoundation.org/networking/netem
```bash
TARGET1='8.8.8.8'
DEV='eth0'
tc qdisc delete dev $DEV root
tc qdisc add dev $DEV root handle 1: prio