Skip to content

Instantly share code, notes, and snippets.

@datavudeja
datavudeja / rasp.py
Created September 17, 2025 20:16 — forked from profsucrose/rasp.py
from dataclasses import dataclass
from typing import Callable, Any, Literal, Type
from enum import Enum
El = int | float | str
S = list[El]
BoolMat = list[list[bool]]
def default_for_type(t: Type) -> El:
@datavudeja
datavudeja / main.py
Created September 17, 2025 20:10 — forked from mypy-play/main.py
Shared via mypy Playground
from enum import Enum, unique, auto
from dataclasses import dataclass
from typing import List, TypeVar, Type
from pathlib import Path
import os
I = TypeVar('I', bound='Input')
@unique
class InputType(Enum):
@datavudeja
datavudeja / status.py
Created September 17, 2025 19:49 — forked from isaquealves/status.py
Status rule
from dataclasses import dataclass
from datetime import datetime
import enum
from functools import reduce
from typing import List, Optional
import uuid
class StatusEnum(enum.Enum):
PENDING: str = "PENDING"
@datavudeja
datavudeja / math_parser.py
Created September 17, 2025 19:32 — forked from ve-ron/math_parser.py
A math calculator parser in python.
# Thanks blanket#1213 https://github.com/blanketsucks for helping.
from dataclasses import dataclass
import enum
import math
class MathError(Exception):
pass
class InavliadSyntax(MathError):
def __init__(self, *args: object) -> None:
@datavudeja
datavudeja / tokenize.py
Created September 17, 2025 19:30 — forked from jorektheglitch/tokenize.py
Simple tokenizer for (extended) math expressions
from abc import ABC
from dataclasses import dataclass
from enum import Enum
from string import ascii_letters, digits
from typing import List, Optional, Union
DELIMITER = Enum("DELIMITER", "COMMA SEMICOLON")
@datavudeja
datavudeja / main.py
Created September 17, 2025 19:29 — forked from io-mi/main.py
Simple Lexer & Parser in Python
from typing import Iterator, Match, TypeVar, Type
from dataclasses import dataclass, field
from enum import Enum
import re
class TokenKind(int, Enum):
NUMBER = 0x01
SYMBOL = 0x02
ASSIGN = 0x03
#!/usr/bin/env python3
# Copyright (c) 2010 Joshua Harlan Lifton.
# See LICENSE.txt for details.
#
# keyboardcontrol.py - Abstracted keyboard control.
#
# Uses OS appropriate module.
"""Keyboard capture and control.
@datavudeja
datavudeja / read_shell.py
Created September 14, 2025 18:34 — forked from timothymillar/read_shell.py
Read the result of a shell command into a pandas dataframe
#! /usr/bin/env python3
import io
import subprocess
import pandas
def read_shell(command, **kwargs):
"""
Takes a shell command as a string and and reads the result into a Pandas DataFrame.
@datavudeja
datavudeja / add_pk_to_sqlite_table.py
Created September 7, 2025 19:13 — forked from RobinL/add_pk_to_sqlite_table.py
Add a primary key to a sqlite table
import re
def get_create_table_string(tablename, connection):
sql = """
select * from sqlite_master where name = "{}" and type = "table"
""".format(tablename)
result = connection.execute(sql)
create_table_string = result.fetchmany()[0][4]
return create_table_string
-- Example from https://www.sqlite.org/lang_with.html#outlandish_recursive_query_examples
CREATE TABLE mandelbrot AS WITH RECURSIVE
xaxis(x) AS (VALUES(-2.0) UNION ALL SELECT x+0.05 FROM xaxis WHERE x<1.2),
yaxis(y) AS (VALUES(-1.0) UNION ALL SELECT y+0.1 FROM yaxis WHERE y<1.0),
m(iter, cx, cy, x, y) AS (
SELECT 0, x, y, 0.0, 0.0 FROM xaxis, yaxis
UNION ALL
SELECT iter+1, cx, cy, x*x-y*y + cx, 2.0*x*y + cy FROM m
WHERE (x*x + y*y) < 4.0 AND iter<28
),