Skip to content

Instantly share code, notes, and snippets.

View svermeulen's full-sized avatar

Steve Vermeulen svermeulen

View GitHub Profile
local record MinHeap<T>
_size: integer
_items: {T}
_comparator: function(T, T):boolean
size: integer
metamethod __call: function(self, comparator?: function(T, T):boolean): MinHeap<T>
end
@svermeulen
svermeulen / Cargo.toml
Last active January 4, 2024 12:25
Adding parent span id to tracing json in Rust
[package]
name = "foo"
edition = "2021"
version = "0.1.0"
authors = ["Steve Vermeulen <sfvermeulen@gmail.com>"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tracing = "0.1.40"
@svermeulen
svermeulen / meta_ops.rs
Created November 9, 2023 12:50
Patches for piccolo project
pub fn index<'gc>(
ctx: Context<'gc>,
table: Value<'gc>,
key: Value<'gc>,
) -> Result<MetaResult<'gc, 2>, TypeError> {
let idx = match table {
Value::String(_) => match ctx.state.globals.get(ctx, "string") {
Value::Table(string_table) => {
let idx = if let Some(mt) = string_table.metatable() {
mt.get(ctx, MetaMethod::Index)
local record Class
__name:string
__init:function(self:Class, ...:any)
end
function setup_as_class(class:Class, name:string):any
class.__name = name
setmetatable(
class, {
__call = function(_, ...):any
@svermeulen
svermeulen / gist:2ebe995ad7e398dc7c707a1be0c87674
Created April 14, 2022 00:34
Lua Teal Interface Example
local record IFoo
bar: function(self:IFoo, integer):integer
end
--------------------
local record Foo1
bar: function(integer):integer
end
@svermeulen
svermeulen / pod.py
Created August 22, 2021 11:02
Dataclass base class example
from jsonpickle.unpickler import loadclass
import jsonpickle
import typeguard # type: ignore
from dataclasses import is_dataclass
import inspect
# The entire purpose of this class is just to hook into the unpickle event
# so that we can call validate_member_types
# We want to be as strict as possible when deserializing
@svermeulen
svermeulen / MoonScriptLineNumberMap.moon
Created February 13, 2021 16:58
How I map moon script line numbers to lua
-- TODO - instead of calculating this every time we should cache the map to file
class MoonScriptLineNumberMap
new: =>
@_fileMapMap = {}
@_jobManager = LazyResolve('JobManager')
_createFileMap: (moonPath) =>
lines = @_jobManager\executeAndWaitGetAllOutputLines("moonc -X '#{moonPath}'")
fileMap = {}
first = true
@svermeulen
svermeulen / LICENSE
Last active September 15, 2021 15:13
MIT License
Copyright (c) 2021 Steven Vermeulen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@svermeulen
svermeulen / linq_python_examples.py
Created January 29, 2020 11:42
Python LINQ equivalents
def assert_throws(func):
try:
func()
except Exception:
return True
return False
def test_empty():
@svermeulen
svermeulen / gist:996213b4c6747c8c20f5a498ca67f932
Last active March 3, 2019 01:52
Hammerspoon to reload karabiner (12.2.0) complex modification. NOTE: Assumes 1 entry and that it's listed at the top in the add popup
hs.urlevent.bind("reloadKarabinerConfig", function(eventName, params)
hs.application.launchOrFocusByBundleID("org.pqrs.Karabiner-Elements.Preferences")
local delay = 10
hs.timer.doAfter(1, function()
-- Select the complex modifications tab
hs.eventtap.keyStroke({}, "right", delay)
hs.eventtap.keyStroke({}, "right", delay)
hs.timer.doAfter(1, function()