Skip to content

Instantly share code, notes, and snippets.

View HirbodBehnam's full-sized avatar

Hirbod Behnam HirbodBehnam

View GitHub Profile
@HirbodBehnam
HirbodBehnam / depot-downloader-splitter.sh
Created November 23, 2022 06:50
Split the files of a steam depot with maximum size of each group
#!/bin/bash
# A manifest file generated from https://github.com/SteamRE/DepotDownloader must be passed to the script.
# It should contain only the file lines.
# Use this script like bash depot-downloader-splitter.sh mainfest.txt 40000000000
rm part*.txt # remove old files
MAX_SIZE=$2 # maximum size of each part
CURRENT_SIZE=0
COUNTER=1
while read -r line; do
line=$(echo $line) # trim each column
@HirbodBehnam
HirbodBehnam / xstat.sh
Last active May 2, 2024 14:04
Get stats of xray in style
xray api statsquery --server=127.0.0.1:10085 | jq -r '.stat | (.[].value |= (. // "0" | tonumber)) | (.[].name |= split(">>>")) | group_by(.name[1]) | (.[] |= {download: (if .[0].name[3] == "downlink" then .[0].value else .[1].value end), upload: (if .[0].name[3] == "downlink" then .[1].value else .[0].value end), name: .[0].name[1], total: (.[0].value + .[1].value)}) | sort_by(.total) | reverse | .[] | .name + " ↓" + (.download / 1024 / 1024 | floor | tostring) + "MB ↑" + (.upload / 1024 / 1024 | floor | tostring) + "MB ↕" + (.total / 1024 / 1024 | floor | tostring) + "MB"' | column -t -s' '
@HirbodBehnam
HirbodBehnam / sni-block-check.go
Created September 29, 2022 06:08
Check if SNI is blocked with Golang
package main
import (
"crypto/tls"
"log"
"net"
)
const hostname = "www.google.com"
const request = "GET / HTTP/1.1\r\nHost: " + hostname + "\r\nConnection: close\r\n\r\n"
@HirbodBehnam
HirbodBehnam / meme-generator.sh
Last active September 3, 2022 16:22
A meme generator based on code of esmBot
#!/bin/bash
# This script is based on esmBot caption command. See code here: https://github.com/esmBot/esmBot/blob/master/natives/caption.cc
# It needs ffmpeg + ffprobe + vips installed. The meme is created with dark mode caption
# I used vips 8.13 and ffmepg build of 2022-06-16
# It must be used like this: bash meme-generator.sh template.png "my caption of meme"
# Font is also available at https://github.com/esmBot/esmBot/blob/master/assets/caption.otf
WIDTH=$(ffprobe -v error -select_streams v -show_entries stream=width -of csv=p=0:s=x "$1")
FONT_SIZE=$((WIDTH/10))
vips text caption.png "<span foreground=\"white\" background=\"black\">$2</span>" --width $WIDTH --font "futura bold $FONT_SIZE" --align centre --rgba
ffmpeg -i caption.png -vf "pad=$WIDTH:ih+$FONT_SIZE:(ow-iw)/2:(oh-ih)/2" caption2.png
@HirbodBehnam
HirbodBehnam / cycle-finder.py
Created July 10, 2022 13:37
Cycle finder for discrete logarithm problem
def find_cyclic(p, g) -> int:
seen = set()
current = g
while True:
current *= g
current %= p
if current in seen:
print(sorted(seen))
print(len(seen))
return len(seen)
package main
import (
"github.com/WolframAlph/dh"
"golang.org/x/crypto/curve25519"
"math/rand"
"testing"
)
func X25519KeyGen() (key []byte, public []byte) {
@HirbodBehnam
HirbodBehnam / merge-pdf.sh
Created May 10, 2022 05:19
Merge pdf files with gostscript and TOC
# From https://stackoverflow.com/a/56154217/4213397
for file in *.pdf; do
filename="${file%.*}"
gs -o "${filename}_toc.pdf" -sDEVICE=pdfwrite -c "[/Title ($filename) /OUT pdfmark" -f "$file"
done
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile=final.pdf *_toc.pdf
@HirbodBehnam
HirbodBehnam / disjoint_set.cpp
Created January 13, 2022 11:00
Simple disjoint set which I don't know if it works or not.
// from https://github.com/spakin/disjoint
class disjoint_set {
private:
typedef struct {
int rank;
int parent;
} element;
vector<element> set_list;
public:
explicit disjoint_set(int size) {
@HirbodBehnam
HirbodBehnam / unicode-decompose.py
Last active January 10, 2022 15:48
This script decomposes the Unicode characters in a text file based on UnicodeData.txt and then creates a json file which can be used in other programming languages for decomposing. I used this script to fix the Persian characters extracted from PDF files.
import re
import json
fixset = {}
# Get this file from http://ftp.unicode.org/Public/UNIDATA/UnicodeData.txt
with open('UnicodeData.txt', 'r') as data:
for line in data:
lineData = line.split(';')
if lineData[5] != '':
g = re.search(r'^<.+> (.+)$', lineData[5])
if g is not None and g.group(1) is not None:
@HirbodBehnam
HirbodBehnam / prim.cpp
Created December 26, 2021 14:23
Simple and inefficient prim algorithm implementation in C++
#include <iostream>
#include <unordered_set>
#include <vector>
using namespace std;
class graph {
private:
typedef struct {
int to;