Skip to content

Instantly share code, notes, and snippets.

View donno2048's full-sized avatar
:octocat:
🍴😴👨‍💻🔁

Elisha Hollander donno2048

:octocat:
🍴😴👨‍💻🔁
View GitHub Profile
@donno2048
donno2048 / main.py
Created April 27, 2024 14:16
motion enhancment
# enhance motion in video, motion is calculated based on the last 10 frames
from cv2 import VideoCapture, VideoWriter_fourcc, VideoWriter, normalize, CAP_PROP_FPS, CAP_PROP_FRAME_WIDTH, CAP_PROP_FRAME_HEIGHT, NORM_MINMAX, CV_8U
from numpy import average
vidcap = VideoCapture("in.mp4")
video = VideoWriter("out.mp4", VideoWriter_fourcc(*"mp4v"), vidcap.get(CAP_PROP_FPS), (int(vidcap.get(CAP_PROP_FRAME_WIDTH)), int(vidcap.get(CAP_PROP_FRAME_HEIGHT))))
success, image = vidcap.read()
last_images = [image] * 10
while success:
motion = (0xff - image + last_images.pop(0)) / 2 # extract motion
motion = average(motion, axis=2, keepdims=True) # greyscale
@donno2048
donno2048 / pi.c
Created September 30, 2023 18:56
// This will calculate pi, the larger the circle the accurate the calculation
// Based on the winning entry of 1988's IOCCC
#include "stdio.h"
#define _ ++y>x&&x++;
long x = 0, y = 0;
int main(void) {
calc();
printf("%f\n", 4. * y / x / x);
}
void calc() {
@donno2048
donno2048 / stupid.js
Created November 6, 2022 19:40
Stupid things in Node.js
// Stupid things in Node.js
NaN == NaN // false
0.1 + 0.2 == 0.3 // false
[] == true // false
!![] == true // true
0 == [] // true
0 == [0] // true
[] == [0] == 0 // true
[] == [0] // false
[] + [] // ''
@donno2048
donno2048 / create.py
Last active September 21, 2022 19:37
the smallest possible "valid" png
# as far as I know this is the smallest possible "valid" png
open("new.png", "wb").write(b'\x89PNG\r\n\x1a\n\0\0\0\rIHDR\0\0\0\1\0\0\0\1\1\0\0\0\x007n\xf9$\0\0\0\1IDAT0')
# I use it to hide files inside "photos" to send on platforms that won't send executable etc. like so:
open("new.png", "wb").write(b'\x89PNG\r\n\x1a\n\0\0\0\rIHDR\0\0\0\1\0\0\0\1\1\0\0\0\x007n\xf9$\0\0\0\xffIDAT' + open("./snake.com", "rb").read())
@donno2048
donno2048 / game.py
Last active September 23, 2022 13:49
Very simple game
from os import environ
environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1'
from pygame import Rect, init, K_LEFT, K_RIGHT, K_UP, K_DOWN, K_RETURN, K_ESCAPE, K_r, K_p, QUIT
from pygame.event import get
from pygame.font import Font
from pygame.key import get_pressed
from pygame.display import set_mode, flip
from pygame.draw import rect
from pygame.time import delay
from random import randint, choice
#include <stdio.h>
void*memset(void*s,int c,int n){}
int main(int argc, char *argv[]) {
while(argc --> 0) argv[argc] = 0;
printf("%s\n", argv);
return 0;
}
/*
`gcc .\main.c -O3 -o main;./main`
and
@donno2048
donno2048 / main.py
Created June 10, 2022 12:05
enable unicode input
# enable "Alt" + "+" + "3" + "3" to write "3" (unicode input)
from winreg import *
SetValueEx(OpenKey(HKEY_CURRENT_USER, r"Control Panel\Input Method", 0, KEY_ALL_ACCESS), "EnableHexNumpad", 0, 1, "1")
@donno2048
donno2048 / main.py
Created May 9, 2022 10:09
Python plus plus
from pypp import Str, Int, Float, cout, cin, endl
if __name__ == "__main__":
str1, str2, int1, float1 = Str(), Str(), Int(), Float()
cout << "Hello, " << "world!" << endl
cin >> str1 >> str2 >> int1 >> float1
cout << str1 << endl << str2 << endl << (int1 + Int(1)) << endl << float1 << endl
@donno2048
donno2048 / main.py
Last active April 24, 2022 18:28
Inverse square root and fast inverse square root
# Inverse square root and fast inverse square root
from ctypes import c_long, c_float, addressof, cast, POINTER
def fisr(number: float) -> float:
y = c_float(number)
i = c_long(0x5f3759df - (cast(addressof(y), POINTER(c_long)).contents.value >> 1))
y = cast(addressof(i), POINTER(c_float)).contents.value
return y * (3 - (number * y * y)) / 2
"""
float fisr(float number) {
float y = number;
flowchart TD
    A[Why do you want to learn programming?] -- Fun --> B[Simplicity or Efficiency?];
    B -- Simplicity --> C[Is portability important?];
    C -- Yes --> D{JS};
    C -- No --> E[Aesthetics or Clearness?];
    E -- Aesthetics --> F{Ruby};
    E -- Clearness --> G[Ease or Versatility?];
    G -- Ease --> H{Python};
    G -- Versatility --> I{Lua};