Skip to content

Instantly share code, notes, and snippets.

View midnqp's full-sized avatar
:octocat:
Make very sure to have fun opensourcing!

Muhammad Bin Zafar midnqp

:octocat:
Make very sure to have fun opensourcing!
View GitHub Profile
@midnqp
midnqp / Singleton.ts
Last active November 6, 2023 04:26
This is a singleton class implementation using `constructor()` in TypeScript.
import crypto from 'node:crypto'
class Singleton {
private static instance?:Singleton|null
constructor() {
if (Singleton.instance) return Singleton.instance
if (Singleton.instance === undefined) {
Singleton.instance = null
/**
* Runs the `idempotentFn` for ~4400ms, in an interval
* of 50ms - to satisfy `testFn`. If unsatisfied, throws Error(`msg`).
*
* @param idempotentFn - a function that can be executed ∞ times
* without a side-effect.
* @param testFn - throw if unsatisfied; if no throw, then return perfectly ✓!
* @param msg - error message to throw if no luck at all
*/
async function waitAndSee (idempotentFn, testFn, msg) {
@midnqp
midnqp / main.c
Created August 18, 2022 15:18
C/C++ code using libcpy.h
#include <cpy.h>
int main() {
char* name = new(Str_t);
List* ls = new(List_t);
bool t = type(ls) == List_t; //true
double arr[] = { 1.2, -3.4 };
input(name, "👨🏻‍💻 Username: ");
listAdd(ls, 1.2, -3.4, name);
@midnqp
midnqp / compile-vim-linux-amd64.sh
Last active December 14, 2021 10:01
Compile the latest Vim from source code to have the most features, `hugecompile`. The flag `+clipboard` lets you sync clipboard between OS and Vim copy (yank).
#!/bin/bash
# Copyright 2021 Muhammad <midnqp@gmail.com>
# Compile Vim with huge features and +clipboard.
# To yank directly to system clipboard...
# vim: set clipboard=unnamedplus
# It is advisable that you remove your installation of Vim.
# You need +python3 for YouCompleteMe. Don't use Python2.