Skip to content

Instantly share code, notes, and snippets.

View MHM5000's full-sized avatar
🏠
Working from home

Mohammad Hossein Mojtahedi MHM5000

🏠
Working from home
View GitHub Profile
#!/usr/bin/env python
import multiprocessing
import random
import time
class Logger:
def __init__(self, num_lines, last_output_per_process, terminal_lock):
self.num_lines = num_lines
import React from "react";
import {
FiBell,
FiDownload,
FiEdit,
FiSave,
FiSettings,
FiUser,
} from "react-icons/fi";
import { SiAirbnb } from "react-icons/si";
@hyperupcall
hyperupcall / settings.jsonc
Last active May 3, 2024 12:52
VSCode config to disable popular extensions' annoyances (telemetry, notifications, welcome pages, etc.)
// I'm tired of extensions that automatically:
// - show welcome pages / walkthroughs
// - show release notes
// - send telemetry
// - recommend things
//
// This disables all of that stuff.
// If you have more config, leave a comment so I can add it!!
{
@jab3z
jab3z / log_io.py
Last active October 9, 2022 07:29
Python decorator for logging the input and output of a class method
import inspect
import logging
from functools import wraps
from typing import Callable
def log_io(log_input=False, log_output=False) -> Callable:
"""
Logs the input/output of the decorated method.
Must be explicitly called with input=True and/or output=True
@ramkumarvenkat
ramkumarvenkat / dreamland.md
Last active January 2, 2024 11:40
Dreamland technical question

Dreamland is a new age AI+metaverse company and has a concept of games, where every user can play these games with AI agents and win DREAM tokens multiple times a day. A user can win upto 5 DREAM tokens on a single day.

DREAM tokens are a virtual currency and have a real monetary value. At the end of every hour, the tokens won by the user are converted to USD by calling a third-party API that provides the rate (for the assignment, we can hardcode to 15 cents per token).

Every time a user is issued a token and it gets converted to USD, there will be fees which we need to keep track of (the user will not bear the fees, but Dreamland will)

In the backend, there are double-entry accounting ledgers that keep track of a user's tokens, the current USD value and the fees.

Imagine you are building APIs for Dreamland:

@huytd
huytd / wordle.md
Last active May 2, 2024 12:13
Wordle in less than 50 lines of Bash

image

How to use:

./wordle.sh

Or try the unlimit mode:

@sindresorhus
sindresorhus / esm-package.md
Last active May 4, 2024 15:48
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@geek-at
geek-at / trash.sh
Created August 13, 2020 07:27
The script used to trash a banking phishing site
#!/bin/bash
while :; do
verf=$(cat /dev/urandom | tr -dc '0-9' | fold -w 8 | head -n 1)
pin=$(cat /dev/urandom | tr -dc '0-9' | fold -w 5 | head -n 1)
ip=$(printf "%d.%d.%d.%d\n" "$((RANDOM % 256))" "$((RANDOM % 256))" "$((RANDOM % 256))" "$((RANDOM % 256))")
@miraculixx
miraculixx / markup.py
Last active April 12, 2023 17:13
an extensible multi-markup reader in less than 100 lines of python code
# (c) miraculixx, licensed as by the terms of WTFPL, http://www.wtfpl.net/txt/copying/
# License: DO WHATEVER YOU WANT TO with this code.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
from io import StringIO
from contextlib import contextmanager
@MHM5000
MHM5000 / windows-host-linux-guest-virtualbox-increase-vdi-fixed-size.md
Created May 13, 2020 06:17
Increase an Ubuntu/Linux virtualbox fixed size viratual disk image (guest) on a Windows 10 (host)

Disclaimer: I just did these steps once after 2 hours of research on a VirtualBox Version 6.0.10 r132072 (Qt5.6.2) installed on Windows 10 and it worked. Make sure you know what you are doing.

Let's assume these:

  • Your VM VirtualBox installation folder is: C:\Program Files\Oracle\VirtualBox
  • Your VM files are in D:\VM\ubuntu\18.04\.
  • fixed-18.04.vdi is a 40GB fixed size storage that we want to resize.

Steps:

  1. Shutdown your Ubuntu VM.