Skip to content

Instantly share code, notes, and snippets.

View osnr's full-sized avatar

Omar Rizwan osnr

View GitHub Profile
/* ~/Library/KeyBindings/DefaultKeyBinding.dict */
{
/*
* Keybindings for emacs emulation.
*
* WARNING! After Mountain Lion, this file cannot be symbolic linked to another file,
* you need to put this file in ~/Library/KeyBindings/DefaultKeyBinding.dict directly
*
* Reference:
@osnr
osnr / tap.swift
Created December 22, 2017 21:27
//
// ScreenCapture.swift
// Screenotate
//
// Created by Omar Rizwan on 7/6/17.
// Copyright © 2017 Omar Rizwan. All rights reserved.
//
import Foundation
import Cocoa
// should work with tcc 0.9.27 from: https://bellard.org/tcc/ which I
// think merges minimal Darwin support from https://github.com/andreiw/tinycc
// (I think only `-run` works; it can't output a Mach-O executable?)
//
// but the header and libc situation on macOS for non-GCC/clang is
// such an incredible mess -- I did kinda get it working, but it's
// more fun to just write something that calls directly into the OS &
// has no dependencies (:
//
// $ tcc -nostdlib -nostdinc -run minimal-osx-tcc-hello.c
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
@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); {
@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 / 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 */
);
-- 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 / 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;
<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); }