Skip to content

Instantly share code, notes, and snippets.

View llandsmeer's full-sized avatar
💡

Lennart Landsmeer llandsmeer

💡
View GitHub Profile
<!doctype html>
<meta charset="utf-8">
<div id=live style='overflow-wrap: break-word; font-family: monospace'></div>
<script>
class Controller {
constructor(ip) {
this.ip = ip
this.connect()
import json
import random
import time
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
import numba
@numba.jit(fastmath=True, cache=True, nopython=True)
def simulate(transient=10, seconds=1, delta=0.015, record_every=10):
@llandsmeer
llandsmeer / master_recipe.py
Created January 19, 2022 23:58
Arbor master recipe v1
import arbor
class master_recipe(arbor.recipe):
def __init__(self, *recipes):
arbor.recipe.__init__(self)
self.recipes = list(recipes)
self.setup_master_recipe()
### :::THIS IS THE ONLY PROBLEM:::
### global_properties() can not be specified up to subrecipe level
### which means catalogue mechanism names can not collide
@llandsmeer
llandsmeer / heat_equation_delta_sources.py
Created January 14, 2022 16:46
Poisson problem with dirichlet b.c. as grad=0 at the unit square edges and a list of source nodes (useful for heat sensor data interpolation)
# Dirichlet bc eliminated
import numpy as np
import matplotlib.pyplot as plt
import scipy.sparse as sp
import scipy.sparse.linalg as spla
N = 64
sources = [
(0.3, 0.3, 15),
(0.7, 0.7, 25)
@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
@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 / 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 / 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 / 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: