Skip to content

Instantly share code, notes, and snippets.

View iAnatoly's full-sized avatar

Anatoly Ivanov iAnatoly

View GitHub Profile
@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
go install -v github.com/projectdiscovery/dnsx/cmd/dnsx@latest
go install -v github.com/projectdiscovery/subfinder/v2/cmd/subfinder@latest
brew install ipinfo-cli
./go/bin/subfinder -d google.com | ./go/bin/dnsx -resp-only | ipinfo summarize
@iAnatoly
iAnatoly / MACOS-LIST.md
Last active April 13, 2022 18:24
List of tools to make MacOS usable
  • iTerm2
  • iStat menus
  • VS code
  • ObjeciveSee: BlockBlock, KnockKnock
  • Homebrew: ansible, telegraf, bash5, curl, wget, sqlite, python3, go,
  • Commons: Chrome, Chromium, FF, Kindle, VLC
SSH_ENV="$HOME/.ssh/agent-environment"
function start_agent {
echo "Initialising new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add;
}