Skip to content

Instantly share code, notes, and snippets.

View alifarazz's full-sized avatar
🐊

Ali Farazdaghi alifarazz

🐊
View GitHub Profile
@alifarazz
alifarazz / smallest_pair.py
Last active June 3, 2020 18:05
Get minimum Euclidean distance between points in an XY plane using O(n.lgn).
from scipy import spatial
import numpy as np
pos = np.c_[np.random.rand(100), np.random.rand(100)]
tree = spatial.cKDTree(pos)
dist, ids = tree.query(pos, 2)
print(f'min dist: {np.min(dist[:, 1]): 8f}')
@alifarazz
alifarazz / cache_page.c
Created May 17, 2020 11:06
Show Cache and Page Info
#include <stdio.h>
#include <unistd.h>
int main()
{
puts("L1 I-cache:");
printf("\tSize: %li\n", sysconf(_SC_LEVEL1_ICACHE_SIZE));
printf("\tAssoc: %li\n", sysconf(_SC_LEVEL1_ICACHE_ASSOC));
printf("\tLinesize: %li\n", sysconf(_SC_LEVEL1_ICACHE_LINESIZE));
@alifarazz
alifarazz / mp3_cleanup.py
Last active February 26, 2021 22:54
Cleanup mp3 files metadata with eyed3 python library.
import eyed3
import glob
def f(filename):
audiofile: eyed3.mp3.Mp3AudioFile = eyed3.load(filename)
# print(type(audiofile))
title = audiofile.tag.title.replace('GOOz', '')
trackNumber = int(filename.split()[0])
# print(title, trackNumber)
@alifarazz
alifarazz / README.md
Last active March 13, 2024 07:28
Async echo server and echo client written in python 3.7

Async echo server and echo client written in python 3.7

Dependencies

  • aioconsole

How to run

  • echo server: python echo-server.py <IP>
  • echo client: python echo-client <IP> <port>
  • Use localhost as IP and 10000 or 10001 as port.
@alifarazz
alifarazz / zkill.fish
Created October 16, 2019 19:20
Uses fzf to select a process and sends SIGKILL to it.
function zkill
set pid_name (ps -ef | fzf | awk '{print $2; print $8}')
set pid $pid_name[1]
if test -n "$pid"; and string match -qr '^[0-9]+$' "$pid"
kill -9 $pid
echo Killed {$pid_name[2]} with pid: $pid
else
echo Nothing done.
# echo $pid
from tqdm import tqdm
from bs4 import BeautifulSoup as bs
import requests
import math
url = 'http://dl.yektamusic.ml/Artist/Ebi/'
r = requests.get(url)
s = bs(r.content, 'html.parser')
@alifarazz
alifarazz / duff.c
Last active September 26, 2019 07:39
A simple implementation of Duff's device
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
int n, i;
if (argc != 2)
return 1;
@alifarazz
alifarazz / Makefile
Created April 30, 2019 17:47
A Linux process cloning example using Clone().
all: default
default: waitpid waitpid_optimized
waitpid: waitpid.c Makefile
$(CC) -Wall -Werror -std=gnu17 -ggdb -o waitpid waitpid.c
waitpid_optimized: waitpid.c Makefile
$(CC) -Wall -Werror -std=gnu17 -Ofast -o waitpid_optimized waitpid.c
@alifarazz
alifarazz / core.clj
Last active May 8, 2019 14:32
Given 4 bank accounts and 10 accountants, write a program to simulate the withdrawal and deposits done by accountants.
(ns bank-acc-sim.core
(:gen-class))
(import '(java.util.concurrent Executors))
(defn bank-sim [naccounts nthreads init-val niters]
(let [refs (map ref (repeat naccounts init-val))
pool (Executors/newFixedThreadPool nthreads)
tasks (map
@alifarazz
alifarazz / docker-compose.yml
Created January 7, 2019 21:22
phpmyadmin and mysql docker-compose file
version: '3.1'
services:
mysql_inst:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
# ports:
# - 8083:3306
volumes: