Skip to content

Instantly share code, notes, and snippets.

View osnr's full-sized avatar

Omar Rizwan osnr

View GitHub Profile
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 */
);
@osnr
osnr / x.lua
Created October 15, 2020 22:25
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 */
);
@osnr
osnr / jit.c
Created August 17, 2020 05:09
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
const char TEXTSENTINEL[] = "__TEXTSENTINEL";
size_t assemble(const char* asmsrc, uint8_t* execbuf, size_t execbuflen) {
char asmpath[] = "/tmp/asm-XXXXXX"; mkstemp(asmpath); {
tell application "System Events"
tell process "Firefox Nightly"
set tmp to value of attribute "AXEnhancedUserInterface"
set value of attribute "AXEnhancedUserInterface" to true
set returnUrl to value of attribute "AXValue" of text field 1 of combo box 1 of toolbar "Navigation" of UI element 1 of front window
set value of attribute "AXEnhancedUserInterface" to tmp
return returnUrl
end tell
end tell