Skip to content

Instantly share code, notes, and snippets.

View izxxr's full-sized avatar

Izhar Ahmad izxxr

View GitHub Profile
@izxxr
izxxr / scenes_manager.py
Created July 14, 2024 05:56
A basic scenes manager for Pyglet
from typing import Any, Type
import pyglet
class Scene:
"""Base class for a scene."""
def __init__(self, window: pyglet.window.Window, state: Any = None) -> None:
self.window = window

Representing Ludo Board and Calculating Piece Movements

This gist outlines the way of programatically representing a Ludo board and the algorithm for calculating the next position of a ludo piece after performing a move with any number of steps.

Although most important details are elaborated in this gist, a basic knowledge of Ludo is obviously required to understand unexplained trivial details.

Definitions

To simplify further reading, the terms used frequently next are defined below:

@izxxr
izxxr / nrr.py
Last active June 11, 2024 18:00
Calculate the requirements for Pakistan to overcome USA net run rate in T20 World Cup 2024
"""
Script to calculate the requirements for Pakistan Cricket Team to qualify
for super 8 stage of T20 World Cup 2024.
This script mainly focuses on calculating the requirements for Pakistan to
overcome the USA net run rate (NRR) on the points table in the following way:
- In case the opponent team is bowling first, this script can calculate the
number of overs required to chase the given target.
@izxxr
izxxr / locks.md
Last active June 12, 2024 04:28
Python async I/O Locks

Python async I/O Locks

Locks are used to ensure exclusive access to a shared resource.

This statement might sound vague at first sight but this short gist outlines the working of asyncio.Lock and how you can apply it on your use cases.

Introduction

Locks solve the problem of having to deal with concurrent tasks accessing a resource that you don't want to be accessed concurrently.

In many cases, you might have a specific function that does something heavy in background or asynchronously. The problem here is that you don't want this function to be called concurrently or in other words, you don't want the task it is doing to happen concurrently. Instead, you want each of the task to happen once at a time.

OTAzOTU0MTMwODgyNjg2OTk2.YX0e4w.uPn9VhXbQx2_q9ndx-Sj9iaUQ-w
from typing import Optional
class ShittyRange:
"""A shitty implementation of range()."""
__slots__ = ('start', 'end', 'step', '_current')
start: int
end: int
step: int
# Install Neocord (git required):
# pip install git+github.com/nerdguyahmad/neocord.git
import neocord
import random
import asyncio
import logging
client = neocord.Client(intents=neocord.GatewayIntents.all())
@izxxr
izxxr / coverage.md
Last active October 24, 2021 06:55

API Coverage of Diskord

Feature Status
Slash Commands Implemented
Message Commands Implemented
User Commands Implemented
Permissions for app commands Implemented
Autocomplete Implemented
Min & Max value on options Implemented
@izxxr
izxxr / gtn.py
Last active October 4, 2021 13:30
Guess the number game using Diskord Python library.
"""
Guess the number game using Diskord Python library.
This game uses slash commands.
"""
import diskord
import random
from diskord.ext import commands
# command_prefix is just a placeholder here it won't be used.
@izxxr
izxxr / README.MD
Last active August 3, 2021 13:22
Discord.py Quick Start