Skip to content

Instantly share code, notes, and snippets.

View omaraflak's full-sized avatar
👨‍💻
hey you

Omar Aflak omaraflak

👨‍💻
hey you
View GitHub Profile
@omaraflak
omaraflak / oracle.py
Last active February 13, 2024 16:16
Based on Aaronson Oracle
import sys
import getch
from collections import defaultdict
class Oracle:
def __init__(self, window_size: int):
self.window_size = window_size
self.window: str = ''
self.patterns: defaultdict[str, dict[str, int]] = defaultdict(lambda: defaultdict(int))
<canvas id="canvas"></canvas>
<script>
const WIDTH = 1500
const HEIGHT = 800
const canvas = document.getElementById("canvas")
const ctx = canvas.getContext("2d")
canvas.width = WIDTH
canvas.height = HEIGHT
@omaraflak
omaraflak / automata.py
Last active January 10, 2024 00:39
Wolfram Cellular Automata
def print_cells(cells: list[int]):
print(''.join('■' if i == 1 else ' ' for i in cells))
def next_step(cells: list[int], rules: list[int]) -> list[int]:
new_cells: list[int] = [False] * len(cells)
for i in range(len(cells)):
left = cells[(i - 1) % len(cells)]
right = cells[(i + 1) % len(cells)]
idx = int(''.join([str(left), str(cells[i]), str(right)]), 2)
@omaraflak
omaraflak / cv2_canvas.py
Created August 22, 2023 15:53
cv2 canvas
import cv2
import numpy as np
size = 28
drawing = False
win_name = "Draw digit"
def draw(event, x, y, flags, *param):
global drawing
if event == cv2.EVENT_LBUTTONDOWN:
@omaraflak
omaraflak / canvas.html
Created October 16, 2022 19:17
JS canvas get started template
<canvas id="canvas"></canvas>
<script>
const WIDTH = 500
const HEIGHT = 500
const canvas = document.getElementById("canvas")
const ctx = canvas.getContext("2d")
canvas.width = WIDTH
canvas.height = HEIGHT
@omaraflak
omaraflak / moon.py
Created July 16, 2022 15:57
Moon API
from dataclasses import dataclass
from datetime import datetime, timezone, timedelta
from pylunar import MoonInfo
def datetime_to_tuple(date: datetime) -> tuple[int, int, int, int, int, int]:
return (date.year, date.month, date.day, date.hour, date.minute, date.second)
def min_points(x: list[int], y: list[float]) -> tuple[list[int], list[float]]:
@omaraflak
omaraflak / projection.py
Last active July 11, 2022 19:42
3D projection
import cv2
import numpy as np
import plotly.graph_objects as go
image = cv2.imread("earth.jpeg", cv2.IMREAD_COLOR)
height, width, _ = image.shape
image = cv2.resize(image, (300, int(height * 300 / width)))
height, width, _ = image.shape
@omaraflak
omaraflak / vortex.py
Last active February 20, 2022 20:52
Vortex
import numpy as np
from matplotlib import collections as mc, pyplot as plt
Point = tuple[float, float]
Line = tuple[Point, Point]
def get_lines(multiplier: int, modulus: int) -> list[Line]:
start = np.arange(1, modulus)
end = start * multiplier % modulus
angle = 2 * np.pi / modulus
@omaraflak
omaraflak / point.py
Created December 25, 2021 14:03
Tree fractal
# geometry/point.py
import math
from dataclasses import dataclass
from typing import Optional
@dataclass
class Point:
x: float = 0
@omaraflak
omaraflak / landau.py
Created August 18, 2021 10:15
Landau's Function
from math import gcd
from functools import reduce
from typing import Iterator
def lcm(nums: list[int]) -> int:
_lcm = lambda a, b: (a * b) // gcd(a, b)
return reduce(_lcm, nums)
def partitions(n: int, s: int = 1) -> Iterator[int]:
yield (n,)