Skip to content

Instantly share code, notes, and snippets.

View itamarst's full-sized avatar

Itamar Turner-Trauring itamarst

View GitHub Profile
@itamarst
itamarst / wgpu_example.py
Created February 14, 2024 13:37
wgpu example
from wgpu.utils.compute import compute_with_buffers
from wgpu.utils import get_default_device
import numpy as np
from time import time
# A "shader"" is a program that will run on the GPU:
SHADER = """
@group(0) @binding(0)
var<storage,read> input1: array<i32>;
@itamarst
itamarst / example.py
Last active December 15, 2023 14:49
Optimized Numba kernel
@numba.jit(nopython=True, parallel=True, fastmath=True)
def spatial_regularisation_numbaoptimized(x: np.ndarray, dy: int = 1, dx: int = 1) -> float:
ny, nx = x.shape
total_cost = 0.0
for i in numba.prange(ny):
i = numba.int64(i)
min_y = max(i - dy, 0)
max_y = min(i + dy + 1, ny)
for j in numba.prange(nx):
@itamarst
itamarst / lint.sh
Created February 6, 2023 16:34
Lint script for Tahoe-LAFS
#!/bin/bash
set -euo pipefail
flake8 src/
python -m coverage run --branch -m twisted.trial "$@"
coverage combine
coverage xml
diff-cover coverage.xml --compare-branch origin/master --html-report ~/temp/tahoe-coverage.html
firefox ~/temp/tahoe-coverage.html
## dmesg -w -T | grep -i igc
```
[Tue Nov 8 12:28:33 2022] igc 0000:02:00.0: PTM enabled, 4ns granularity
[Tue Nov 8 12:28:33 2022] igc 0000:02:00.0 (unnamed net_device) (uninitialized): PHC added
[Tue Nov 8 12:28:33 2022] igc 0000:02:00.0: 4.000 Gb/s available PCIe bandwidth (5.0 GT/s PCIe x1 link)
[Tue Nov 8 12:28:33 2022] igc 0000:02:00.0 eth0: MAC: d8:5e:d3:af:21:82
[Tue Nov 8 12:28:33 2022] igc 0000:02:00.0 enp2s0: renamed from eth0
[Tue Nov 8 12:28:41 2022] igc 0000:02:00.0 enp2s0: NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX/TX
[Tue Nov 8 13:03:38 2022] igc 0000:02:00.0 enp2s0: PCIe link lost, device now detached
@itamarst
itamarst / example.py
Created March 31, 2020 21:06
Typing Ctrl-C in Powershell interrupts the input() with KeyboardInterrupt, so why doesn't GenerateConsoleCtrlEvent?
import threading
import time
from _thread import interrupt_main
import signal
import os
import ctypes
def interrupter():
time.sleep(1) # make sure input() is waiting
print("Interrupting!")
@itamarst
itamarst / out.txt
Created February 13, 2019 16:03
I ♥ conda
$ conda update -n base -c defaults conda
Solving environment: done
==> WARNING: A newer version of conda exists. <==
current version: 4.5.11
latest version: 4.6.3
Please update conda by running
In [4]: df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]}, index=["x", "y", "z"])
In [5]: df
Out[5]:
a b
x 1 4
y 2 5
z 3 6
In [6]: df["a"]
@itamarst
itamarst / gist:3343845de05a1e3a93fb
Last active August 29, 2015 14:07
Output of linkcheck.py
[ /#0 3fba6baf-8125-4f7c-8c1b-8f687d8a22d3 17:05:44.321218Z
action_type: "check_links"
action_status: "started"
url: "http://example.com"
[ /1/#0 3fba6baf-8125-4f7c-8c1b-8f687d8a22d3 17:05:44.321330Z
action_type: "download"
action_status: "started"
url: "http://example.com"
@itamarst
itamarst / gist:947474a4e00d358892fe
Last active August 29, 2015 14:04
Effect-inspired library idea aimed at unit testing Deferred-using code
# my_effect.py
"""
In normal code, side-effecty code is run as usual.
In tests one can (with a context manager, perhaps) disable side-effects and figure out
what the intention of the code is without actually triggering any side-effects.
"""
class IEffect(Interface):
def run():
@itamarst
itamarst / gist:8378860
Created January 12, 2014 00:28
pip install boom
------------------------------------------------------------
/home/itamar/.local/bin/pip-3.3 run on Sat Jan 11 19:15:31 2014
Downloading/unpacking svn+ssh://[email protected]/svn/Twisted/branches/python3-setup-6539
Checking out svn+ssh://[email protected]/svn/Twisted/branches/python3-setup-6539 to ./pip-qk0ee4-build
Found command 'svn' at '/usr/bin/svn'
Running command /usr/bin/svn checkout -q --username itamarst svn+ssh://[email protected]/svn/Twisted/branches/python3-setup-6539 /tmp/pip-qk0ee4-build
Running setup.py egg_info for package from svn+ssh://[email protected]/svn/Twisted/branches/python3-setup-6539