Skip to content

Instantly share code, notes, and snippets.

View alifarazz's full-sized avatar
🐊

Ali Farazdaghi alifarazz

🐊
View GitHub Profile
@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;
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 / 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
@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 / 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 / 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 / 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}')
##
# Div by 10 in x64
#
# @file
# @version 0.1
.PHONY: default all run clean
default: a
all: default
@alifarazz
alifarazz / tictactoe.py
Last active January 20, 2021 07:59
TicTacToe using minmax and alpha-beta pruning
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
class Table:
def __init__(self, table=None):
empty = [3 * [" "], 3 * [" "], 3 * [" "]]
self.table = table if table else empty
def __delitem__(self, key) -> None:
self.table.__delattr__(key)
@alifarazz
alifarazz / soa_sort.cc
Last active April 3, 2021 01:59
Sort a struct of arrays using an extra array as indexer (therefore, with one level of indirection)
#include <algorithm>
#include <array>
#include <iostream>
#include <random>
#include <string_view>
const int LEN = 10;
using Indexer = int;