Skip to content

Instantly share code, notes, and snippets.

View Moosems's full-sized avatar
👨‍💻
Still programming!

Moosems Moosems

👨‍💻
Still programming!
  • United States
  • 15:45 (UTC -05:00)
View GitHub Profile
@Moosems
Moosems / realistic_case.py
Last active November 3, 2024 10:14
Extensions statistics
def simulate(n: int, propagation_flags: list) -> int:
steps = 0
expecting_events: int = 0
for i in range(1, n + 1):
if propagation_flags[i - 1]:
steps += expecting_events
expecting_events += 1
steps += 3
@Moosems
Moosems / event_dispatcher.py
Last active October 22, 2024 01:49
Python Event based Loop Dispatcher
"""Implements an event dispatch loop similar to the mainloop in tkinter. The EventDispatcher is NOT asyncronous but should be thread safe."""
# TODO: async variant, test thread safety
from collections import deque
from logging import Logger, getLogger
from queue import PriorityQueue
from random import randint
from time import sleep, time_ns
@Moosems
Moosems / stdin.mojo
Created August 15, 2024 03:53 — forked from thatstoasty/stdin.mojo
Reading from stdin using mojo and recreating the Python input function
from builtin.io import _dup
from memory import UnsafePointer, memcpy
from sys import os_is_windows, external_call
@value
struct stdin:
"""A read only file handle to the stdin stream."""
alias file_descriptor = 0
@Moosems
Moosems / calculator.mojo
Last active September 29, 2023 21:14
Cool Mojo Calculator
# Cool Mojo Calculator
from types.input.input import input
def is_float(given_string: String) -> Bool:
# Given a string, go through each character and check if it is a digit or a dot.
for i in range(len(given_string)):
# If the character is a dot, check if it is the last character in the string.
if given_string[i] == "." and i == len(given_string) - 1:
return False
# Normal case, check if the character is a digit or a dot.
@Moosems
Moosems / Dockerfile
Last active October 17, 2024 12:50
Tkinter Docker App Example
FROM ubuntu:20.04 as builder
FROM python:3.10.7
# Create a user to run the application
RUN apt-get update && \
apt-get -y install sudo
RUN useradd -ms /bin/bash docker && echo "docker:docker" | chpasswd && adduser docker sudo