Skip to content

Instantly share code, notes, and snippets.

@amb
amb / prof.py
Created December 30, 2018 14:18
Simple profiling
import cProfile, pstats, io
def profiling_start():
# profiling
pr = cProfile.Profile()
pr.enable()
return pr
def profiling_end(pr):
# end profile, print results
@amb
amb / gl_compute.py
Created July 29, 2019 20:52
Blender Python OpenGL compute shaders
import bgl
import bpy
import numpy as np
def install_lib(libname):
from subprocess import call
pp = bpy.app.binary_path_python
call([pp, "-m", "ensurepip", "--user"])
call([pp, "-m", "pip", "install", "--user", libname])
@amb
amb / most_used_commands.py
Created August 24, 2019 18:43
Report most used Blender commands for the session and sort them by use count
import bpy
import re
from collections import defaultdict
print("---------------- RERUN ----------------")
reports = [bpy.data.texts.remove(t, do_unlink=True)
for t in bpy.data.texts
if t.name.startswith("Recent Reports")]
bpy.ops.ui.reports_to_textblock()
@amb
amb / oculus_touch_osc_stream.py
Last active June 10, 2020 23:56 — forked from awesomebytes/htc_vive_controller_keypresses.py
Oculus Touch streaming with pythonosc and openvr
# forked from: https://gist.github.com/awesomebytes/75daab3adb62b331f21ecf3a03b3ab46
import time
import openvr
from pythonosc import osc_message_builder
from pythonosc import osc_bundle_builder
from pythonosc import udp_client
def get_controller_ids(vrsys=None):
@amb
amb / gist:7c6a75202c0b4211a192de90eefe4e81
Created July 6, 2020 16:30
AHK script for better nav in Fusion 360
; by twitch.tv/floatharr
; rebind fusion360 navigation to be the same as blender emulate mmb
#NoEnv
#InstallKeybdHook
SetKeyDelay, 0
SetMouseDelay, 0
SetControlDelay, 0
SetBatchLines, 0
SendMode input
@amb
amb / chainanalysis.py
Created February 13, 2021 21:06
Simple chainanalysis with Python and Blockcypher
from blockcypher import get_address_details, get_transaction_details
import json
import datetime
def open_chain_info(addr, func):
"cache web API data locally"
def _datetime_conv(o):
if isinstance(o, datetime.datetime):
"""
https://bottosson.github.io/posts/oklab/
Lab
L=lightness
a=green/red
b=blue/yellow
Lab to lightness, chroma, hue (LCh)
C=sqrt(a**2+b**2)
@amb
amb / l3.py
Created March 6, 2021 09:58
Ron Garret l.py Python 3 conversion
# l.py - A tiny interpreter for a lisp-like language with full
# lexical closures in Python
#
# Written by Ron Garret. Contributed to the public domain
# The global environment
# modification 2021 ambi, also public domain
globalenv = {}
@amb
amb / gen_sin_table_fpga.py
Created March 17, 2021 12:19
Generate 7-bit sin table for FPGA/Verilog
import math
for i in range(16):
print(
f"@{(i*16):08x} "
+ " ".join(f"{int(-math.cos((j+i*16)*math.pi*2/255)*127.1+128):02x}" for j in range(16))
)
# for Xilinx Vivado FPGA purposes
# sin_table.mem
from mido import MidiFile
import mido
from collections import defaultdict
import time
import sys
filename = "Space Harrier.mid"
# filename = "Shovel.mid"
if len(sys.argv) == 2: