Skip to content

Instantly share code, notes, and snippets.

View llandsmeer's full-sized avatar
💡

Lennart Landsmeer llandsmeer

💡
View GitHub Profile
@llandsmeer
llandsmeer / qt5_opengl.py
Last active October 4, 2018 22:55
Minimal PyQt5 + PyOpenGL Widget (with debug logging and ctrl-c exit)
import sys, ctypes, signal
from OpenGL import GL, GLU
from PyQt5 import QtCore, QtGui, QtWidgets
position_data = (ctypes.c_float*12)(
-1,-1, 1,-1, -1,1, 1,-1, 1,1, -1,1)
vertex_shader = (GL.GL_VERTEX_SHADER, '''
#version 150
@llandsmeer
llandsmeer / lineprof.py
Created November 5, 2018 04:15
Simple ugly single file line by line real time python profiler
#!/usr/bin/env python3
import threading
import re
import signal
import os
import curses
import keyword
import sys
import time
import ast
@llandsmeer
llandsmeer / b.c
Created February 16, 2020 23:26
Execute instructions inside ptrace tracee... might be one of the ugliest hacks I made to date..
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <wait.h>
#include <assert.h>
#include <errno.h>
#include <sys/signal.h>
#include <sys/types.h>
#include <sys/ptrace.h>
@llandsmeer
llandsmeer / tracexecv2.c
Created March 9, 2020 19:51
Execute syscall in other process
#include <assert.h>
#include <errno.h>
#include <signal.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ptrace.h>
@llandsmeer
llandsmeer / brython_p5js.html
Created August 29, 2021 12:54
p5js + brython with an textarea to edit the code
<!-- edited from https://gist.github.com/t2psyto/7b5e08c4d216cfb8d79a86d676be0642 -->
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.9.0/brython.js"> </script>
<script src="//cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.0/p5.js"></script>
</head>
<body onload='brython()'>
<textarea rows=25 cols=80 name=sourcecode id=sourcecode>
def setup():
import os
try:
import numpy as np
except ImportError:
print('Numpy package not found, install with')
print('pip install numpy')
exit(1)
try:
@llandsmeer
llandsmeer / autosave_mpl_background.py
Last active October 15, 2021 20:24
Automatically save all matplotlib plots to a database
'''
Automatically saves all you matplotlib plot using pickle to a sqlite database
such that you can open them later, interactively.
Put this file somewhere on your PYTHONPATH and add this to your .bashrc
export PYTHONPATH="/path/to/directory"
export MPLBACKEND="module://autosave_mpl_background"
'''
@llandsmeer
llandsmeer / tflfib.py
Last active November 10, 2021 14:25
Tensorflow lite example of fibonacci
import numpy as np
import tensorflow as tf
import tflite_runtime.interpreter as tflite
# Fib function
@tf.function
def fibonacci(n):
a = 0
b = 1
@llandsmeer
llandsmeer / f2x8.py
Last active November 10, 2021 16:36
Stupid float implementation from uint8
import numpy as np
def to_float32(exponent, significand):
assert exponent.dtype == np.uint8
assert significand.dtype == np.uint8
negative = ((exponent & 128) >> 7) == 1
exponent = (exponent & 127).astype(float)-64
value = 2.0**exponent * (1.0 + significand.astype(float) / 256.0)
value[negative] *= -1
return value
@llandsmeer
llandsmeer / ddg.py
Created December 2, 2021 03:11
Get python code snippets from ddg directly from your terminal
#!/usr/bin/env python3
import ast
import sys
import requests
from bs4 import BeautifulSoup
import dbm
import unidecode
import subprocess