Skip to content

Instantly share code, notes, and snippets.

View znnahiyan's full-sized avatar

Zulker Nayeen Nahiyan znnahiyan

View GitHub Profile
@znnahiyan
znnahiyan / Makefile
Last active December 18, 2015 15:08
Two programs to ensure atomic(?) operations on periodic operations by making an entry that stores the last time the operation was done. See comment below for more information, no formatting in here! To compile, download all three of these files and run `make`
CC=g++
CPPFLAGS=-m64 -std=c++11 -pedantic -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wno-switch
BIN=$(patsubst %.cpp,bin/%,$(wildcard *.cpp))
all: $(BIN)
bin/%: %.cpp
mkdir -p bin/
$(CC) $(CPPFLAGS) $< -o $@
@znnahiyan
znnahiyan / server-macro.c
Last active August 30, 2017 17:24
Minimal example code for opening a TCP socket, listening for connections, and outputing incoming data to stdout. Two versions: (a) No error checking, and (b) error checking with macros.
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#define LISTEN_PORT (1234)
#define ASSERT_FATAL(condition, function) \
do { \
if ((condition)) { \
perror((function)); \
@znnahiyan
znnahiyan / mstore.hpp
Last active April 27, 2023 06:24
A class for storing data.
#ifndef UTILS_MSTORE_HPP_INCLUDED
#define UTILS_MSTORE_HPP_INCLUDED
// C++ version of stdlib.h used, so that its memory free() function can be distinguished from mstore::free
#include <cstdlib>
#include <string.h>
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
@znnahiyan
znnahiyan / antidependency.sh
Last active August 17, 2023 19:18
Lists and downloads all the dependencies of a supplied module's name from Wikipedia's servers. Usage: ./antidependency.sh Module:NAME1
#!/bin/bash
##
## Maintainer: [[User:Nahiyan8]] @ Wikimedia (en, bn)
## Copyright: Public domain, but I don't think anyone will be able to modify this...
## Created in: 2014-11-22
## Last modified: 2014-11-22
##
##
@znnahiyan
znnahiyan / in.txt
Last active August 30, 2017 12:16
A sudoku solver using simple backtracking. (C++)
53 7
6 195
98 6
8 6 3
4 8 3 1
7 2 6
6 28
419 5
8 79
@znnahiyan
znnahiyan / Test.cpp
Last active February 26, 2021 19:09
Standalone C++20 3D vectors class (templated and with arithmetic operations defined)
#include <iostream>
#include "Vec3.hpp"
int main() {
Vec3<int> first = {1, 2, 3};
Vec3<int> second = first + 2;
Vec3<double> third = first + 1.5;
Vec3<double> fourth = 2.5 + first;
Vec3<double> fifth = {1.0, 2.0, 3.0};
@znnahiyan
znnahiyan / date_regex.py
Last active January 5, 2022 10:20
ISO-8601 date regex with leap year validation. Diagram: https://www.debuggex.com/r/XzZWlrzeqE2NZQAu
'''ISO-8601 date regex with leap-year validation.'''
import re
date_regex = re.compile(r"^(\d{4}-((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01])|(0[469]|11)-(0[1-9]|[12][0-9]|30)|02-(0[1-9]|1[0-9]|2[0-8]))|(\d{2}(0[48]|[2468][048]|[13579][26])|([02468][48]|[13579][26])00)-02-29)$")
# Piece-wise regex by month/leap year:
#
# 31 days: Jan/Mar/May/Jul/Aug/Oct/Dec
# \d{4}-(0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01])