Skip to content

Instantly share code, notes, and snippets.

View HirbodBehnam's full-sized avatar

Hirbod Behnam HirbodBehnam

View GitHub Profile
@HirbodBehnam
HirbodBehnam / bitset.cpp
Created November 25, 2021 07:41
Ultra simple implementation of bit set in C++
class bit_set {
private:
uint8_t *data;
public:
explicit bit_set(int size) {
// (size + 7) / 8 is ceiling of size / 8
data = new uint8_t[(size + 7) / 8]();
}
void set(int index) {
@HirbodBehnam
HirbodBehnam / ffmpeg-scripts.sh
Last active March 2, 2025 23:39
FFMpeg scripts I use to convert videos
# Simple FFMPEG scripts I use to convert videos or audios
# The ones with h264_nvenc codec only work with NVidia graphic cards. You also need to install the drives to use them
# The hevc_nvenc codec is pretty fast but the output file size is terrible. So I won't include that in. (Special thanks to Erfan Mojibi)
# The libx265 provides better quality to file size. So we can increase the crf in it (source: https://trac.ffmpeg.org/wiki/Encode/H.265#ConstantRateFactorCRF)
# The tag is provided by @alirezahabib
# Simple convert from webm to mp4. ACC audio codec at 128kb/s. Change 24 to change the quality (higher is worse)
ffmpeg -i in.webm -r 10 -vf "scale=-2:720" -c:v h264_nvenc -cq:v 24 -profile:v high -c:a aac -b:a 128k -strict experimental out.mp4
ffmpeg -i in.webm -r 10 -vf "scale=-2:720" -c:v libx264 -crf 24 -c:a aac -b:a 128k -strict experimental out.mp4
ffmpeg -i in.webm -r 10 -vf "scale=-2:720" -c:v libx265 -crf 28 -c:a aac -b:a 128k -tag:v hvc1 -strict experimental out.mp4
@HirbodBehnam
HirbodBehnam / csv.go
Created June 10, 2021 08:54
A function to convert an array into csv file in go.
package util
import (
"encoding/csv"
"fmt"
"io"
"reflect"
)
// StreamCsv converts an array of an struct to csv
@HirbodBehnam
HirbodBehnam / ipify.rs
Created May 11, 2021 10:40
A function to get your IP address from ipify.org. It doesn't use any libraries and writes raw input in connection.
use std::net::{TcpStream};
use std::io::{Write, BufReader, BufRead};
/// Connects to api.ipify.org and returns your IP address
/// Note that this method does not use any proxies
fn get_ip() -> Result<String, String> {
// at first, try to to connect to ipify
match TcpStream::connect("api.ipify.org:80") {
Ok(mut stream) => {
// create the request header; This is a const value
@HirbodBehnam
HirbodBehnam / c-testcase-generator.sh
Last active March 31, 2021 17:21
A simple script to generate C testcases based on inputs for Quera
#!/bin/bash
# A simple script to generate C testcases based on inputs for Quera
# Place your input files in a folder called "raw-input" with the format of *.txt
# Then run the program with the code filename as the argument and then this script will generate
# the answers based on your program
# Compile the program
gcc -O3 -o program "$1" -lm # I include the math library as well
# Create the output folders if needed
mkdir -p "in" "out"
# Loop all test cases
@HirbodBehnam
HirbodBehnam / maze-viewer.cpp
Created March 3, 2021 17:09
View mazes generated by our maze generator
/**
Maze example:
1e11111111111
1*0*0*0*0*0*1
1110111111101
1*1*0*1*0*1*1
1011111010101
1*0*0*0*1*0*1
11111111111e1
*/
@HirbodBehnam
HirbodBehnam / checker.bat
Created February 28, 2021 13:31
Some scripts for creating test cases for java applications.
@echo off
setlocal EnableDelayedExpansion
javac %1
set /A Counter=1
set ClassName=%1
set ClassName=%ClassName:~0,-5%
:loop
set "i=in%Counter%.txt"
set "o=out%Counter%.txt"
@HirbodBehnam
HirbodBehnam / QueraScoreboardRemover.js
Last active March 2, 2021 12:17
A tampermonkey script to remove the scoreboard from quera
// ==UserScript==
// @name Quera Scoreboard Remover
// @version 2
// @description Remove the scoreboard from quera
// @author Hirbod Behnam
// @match https://quera.ir/course/assignments/*
// @grant none
// ==/UserScript==
(function() {
@HirbodBehnam
HirbodBehnam / chacha20.h
Last active February 7, 2021 19:36
A super simple chacha20 implantation
#include <stdint.h>
#include <string.h>
static uint32_t rotl(uint32_t a, uint32_t b) {
return (a << b) | (a >> (32 - b));
}
static void qr(uint32_t x[], uint32_t a, uint32_t b, uint32_t c, uint32_t d) {
x[a] = x[a] + x[b];
x[d] = rotl(x[d] ^ x[a], 16);
@HirbodBehnam
HirbodBehnam / dark-pdf.js
Created November 12, 2020 15:50
A tampermonkey script to enable dark mode even on local files.
// ==UserScript==
// @name PDF Dark Mode
// @namespace http://tampermonkey.net/
// @version 1
// @description A tampermonkey script to enable dark mode even on local files.
// @author Hirbod Behnam
// @match *://*/*.pdf
// @grant none
// ==/UserScript==