Skip to content

Instantly share code, notes, and snippets.

View alifarazz's full-sized avatar
🐉

Ali Farazdaghi alifarazz

🐉
View GitHub Profile
@alifarazz
alifarazz / Watchdog.py
Created November 19, 2017 13:39
Watches a file, executes commands if the file is updated. (I use it for auto-compilation)
#!/usr/bin/env python3
# -*-coding:utf-8-*-
# usage:
# ./Watchdog.py <subfile> <commands>
# This script takes a <subfile> file and a list of <commands> which it immediately
# executes in a subprocess.
# It kills the subprocess and relaunches it whenever the file changes.
#
@alifarazz
alifarazz / Makefile
Last active April 24, 2018 18:04
Makefile for personal OpenGL develpment.
# compiler
CC=clang++
# linker
LD=$(CC)
# optimisation
OPT=-ggdb
# warnings
WARN=-Wall -Wextra
# standards
STD=c++14
@alifarazz
alifarazz / Makefile
Last active April 24, 2018 18:03
Makefile for personal kernel development.
# change application name here (executable output name)
TARGET=kernel
LINKERSCRIPT=link.ld
# compiler
CC=gcc
ASM=nasm
QEMU=qemu-system-i386 -kernel
LD=ld
#include <stdio.h>
#include <stdint.h>
union ConverterIntChar {
int i;
char c[4];
};
int main()
{
@alifarazz
alifarazz / cut-vertex.cpp
Created December 24, 2018 14:40
find cut-vertices
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
constexpr int MAXN = 100 * 1000;
int mark[MAXN], low[MAXN];
bool visited[MAXN], iscutv[MAXN];
@alifarazz
alifarazz / DijkstraPQ.cpp
Last active December 28, 2020 15:29
Dijkstra's single source shortest path algorithm implemented using priority queue and adjacency vector.
#include <algorithm>
#include <climits>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
const int maxn = 100'000;
using node = pair<long long, int>;
using link = pair<int, int>;
@alifarazz
alifarazz / Dinic.cpp
Created December 25, 2018 10:04
Find Max flow of a network using Dinic's algorithm.
#include <climits>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
constexpr int MAXN{100 * 1000};
struct Edge {
@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:
@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 / 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