Skip to content

Instantly share code, notes, and snippets.

@MitchellKehn
MitchellKehn / excel_drag_to_fill.py
Created January 21, 2024 01:46
[Excel-like drag to fill functionality] Adds drag-to-fill functionality to a QTableView #qt #pyside
from PySide2 import QtWidgets, QtGui, QtCore
def snap_value(value, snap_points, snap_threshold, verbose=False):
"""
Given a value and a list of "snapping points" it can snap to,
snap it to the closest value if it's within the snapping threshold.
"""
if not snap_points: return value
#include "Python.h"
#include "pyerrors.h"
#include <stdarg.h>
#include <stdbool.h>
typedef int (*awaitcallback)(PyObject *, PyObject *);
typedef int (*awaitcallback_err)(PyObject *, PyObject *);
typedef struct _PyAwaitableObject PyAwaitableObject;
@gatesn
gatesn / aiopa.py
Last active May 11, 2025 16:13
PyArrow and Async IO
from typing import AsyncIterator
import pyarrow as pa
class AsyncMessageReader(AsyncIterator[pa.Message]):
"""Wraps an async iterable of bytes into an async iterable of PyArrow IPC messages.
From this it is possible to build an AsyncRecordBatchStreamReader.
"""
max_days = {}
for d in list2: # or list1, works the same
day, month = int(d[:2]), d[2:]
if month not in max_days or day > max_days[month]:
max_days[month] = day
result = [f"{value:02}{key}" for key,value in max_days.items()]
print(f">>> {result}")
import requests
from io import BytesIO
from http import HTTPMethod
from json import JSONDecoder
from requests import Timeout
from requests import HTTPError
from requests import ConnectionError
from requests import JSONDecodeError
from requests import RequestException
from requests import TooManyRedirects
@giuliano-macedo
giuliano-macedo / interesting.md
Last active November 7, 2023 14:50
Interesting python stuff

Interesting python stuff i found messing around with it

1 hash function is random for non non-primitive objects, and it's seed is reset each time the interpreter is ran

Example: python -c "print(hash('hello world'))" generates random numbers, while python -c "print(hash(4.2))" always returns a constant value

2 list.extend method updates itself each time the iterator is called

This code will run forever ( and eat all your RAM ):

@ShabbirHasan1
ShabbirHasan1 / TradeTronAutoLogin.py
Last active February 7, 2023 04:28
TradeTron Auto Login
import os
import sys
import random
from time import sleep
try:
from playwright_recaptcha import recaptchav2
from playwright.sync_api import Playwright, sync_playwright, expect
except (ImportError, ModuleNotFoundError):
os.system(
@ShabbirHasan1
ShabbirHasan1 / black-scholes.c
Created December 26, 2022 08:09 — forked from codeslinger/black-scholes.c
Black-Scholes Option Pricing Model in C
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
double Normal(double);
double N(double, double, double, double, double);
double delta(double, double, double, double, double);
double delta2(double, double, double);
double ND2(double, double, double);
@ShabbirHasan1
ShabbirHasan1 / ExampleUsage.py
Last active February 12, 2024 17:57
Example Usage of GetIVGreeks File and CalcIvGreeks Class
# -*- coding: utf-8 -*-
"""
:description: Example Codes To Use The Python Class Which Calculate Options IV and Greeks
:license: MIT.
:author: Shabbir Hasan
:created: On Thursday December 22, 2022 23:43:57 GMT+05:30
"""
__author__ = "Shabbir Hasan aka DruneMoone"
__webpage__ = "https://github.com/ShabbirHasan1"
__license__ = "MIT"