Skip to content

Instantly share code, notes, and snippets.

View osnr's full-sized avatar

Omar Rizwan osnr

View GitHub Profile
set COLS 3
Wish tag $this is stabilized
Wish $this is outlined green
Wish $this-display has a canvas with settle 2ms width 1024 height 1024
When display /disp/ has width /displayWidth/ height /displayHeight/ &\
display /disp/ has intrinsics /displayIntrinsics/ &\
the pose library is /poseLib/ &\
the quad library is /quadLib/ &\
the quad changer is /quadChange/ &\
$this has resolved geometry /geom/ &\
#!/usr/bin/env python3
"""
Projector Serial Controller
Python terminal program to communicate with projector over serial port
Based on decompiled Android app functionality
(AI-translated from decompiled JAR of https://play.google.com/store/apps/details?id=com.anybeam.osd&hl=en_US)
(com.anybeam.osd.UsbService and com.anybeam.osd.MainActivity)
"""
package require oo
set block {
class C {
procs {}
}
}
set tmp [file tempfile /tmp/blockXXXXXX].tcl
set fd [open $tmp w]; puts $fd $block; close $fd
diff --git a/lib/math.tcl b/lib/math.tcl
index 5bff734..48b7f0c 100644
--- a/lib/math.tcl
+++ b/lib/math.tcl
@@ -1,9 +1,17 @@
namespace eval ::vec2 {
- proc add {a b} {
- list [+ [lindex $a 0] [lindex $b 0]] [+ [lindex $a 1] [lindex $b 1]]
+ set cc [c create]
+ $cc code {
@osnr
osnr / search-twitter-around-screenotate.md
Created February 9, 2021 03:40
Search your tweets around the time you took a screenshot.

If you have a Screenotate screenshot HTML file open in your browser, clicking this bookmarklet will search your old tweets from around the time you took the screenshot, so you can find your original tweet of it (if it exists).

Make a new bookmark with the below as URL, replacing from:rsnous with from:YourTwitterUsername:

javascript:void%20function(){const%20a=new%20Date(document.body.innerHTML.match(/%3Cdd%3E(\d\d\d\d\-\d\d\-\d\d)/)[1]),b=new%20Date(a.getTime());b.setDate(b.getDate()-1);const%20c=new%20Date(a.getTime());c.setDate(c.getDate()+1);const%20d=`from:rsnous%20since:${b.toISOString().slice(0,10)}%20until:${c.toISOString().slice(0,10)}`;window.location.href=`https://twitter.com/search%3Fq=${encodeURIComponent(d)}`}();

Or construct the bookmarklet URL yourself -- here's the source code:

A few years ago, I tried to turn a Pi Zero into a ‘synthetic USB stick’ – where you’d plug it into your laptop and it’d appear like an ordinary flash drive, but the program on the Zero could intercept reads and writes and dynamically generate content. Like a FUSE filesystem, but as a piece of hardware, sort of.

So you could edit a Python file on your laptop, save it to the USB drive, and then the output of your Python code would magically appear as a sibling file on the drive; things like that. I thought it would be particularly cool as a way to get some dynamism and programmability

<html>
<head>
</head>
<body>
<style>
style { display: block; white-space: pre; font-family: monospace; }
div { background: blue; overflow: hidden; resize: horizontal; }
div::before { content: attr(style); }
@osnr
osnr / memoryusage.lua
Created November 26, 2020 09:45
memory usage of current program itself
-- run with LuaJIT on macOS
-- based on excellent answer here: https://stackoverflow.com/questions/63166/how-to-determine-cpu-and-memory-consumption-from-inside-a-process/1911863
local ffi = require('ffi')
ffi.cdef[[
typedef unsigned int __darwin_natural_t;
typedef __darwin_natural_t natural_t;
typedef int integer_t;
typedef __darwin_natural_t __darwin_mach_port_name_t;
-- based on https://www.reddit.com/r/gamedev/comments/jumvi5/dualsense_haptics_leds_and_more_hid_output_report/gcemle4/
-- requires hidapi + run with LuaJIT
local ffi = require('ffi')
ffi.cdef[[
typedef struct hid_device_ hid_device; /**< opaque hidapi structure */
int hid_init(void);
@osnr
osnr / draw.lua
Last active October 19, 2020 10:22
local ffi = require 'ffi'
ffi.cdef[[
typedef struct _XDisplay Display;
typedef struct Screen Screen;
extern Display *XOpenDisplay(
const char* /* display_name */
);
extern int XDefaultScreen(
Display* /* display */
);