Skip to content

Instantly share code, notes, and snippets.

View catwell's full-sized avatar

Pierre Chapuis catwell

View GitHub Profile
@catwell
catwell / paramspec_wrapper.py
Last active February 28, 2025 08:38
ParamSpec + Concatenate + higher-order function wrapper
# See https://julien.danjou.info/p/the-hidden-cost-of-badly-typed-python
# Simple version (hardcoded types)
from collections.abc import Callable
from typing import Any, Concatenate, ParamSpec
P = ParamSpec("P")
def send_request(client: "HttpClient", method: str = "GET", timeout: int = 5) -> str:
@catwell
catwell / 0-README.md
Last active May 28, 2024 17:57
Avoiding N+1 queries in Strawberry GraphQL with DataLoaders
@catwell
catwell / nested.lua
Last active April 30, 2024 07:54
Lua nested coroutines
-- mini scheduler
local tasks = {} -- execution delays in ticks, indexed by the coroutine
local delay_mt = {}
local function is_delay(x)
return type(x) == "table" and getmetatable(x) == delay_mt
end
local function make_delay(t)
@catwell
catwell / cloc.txt
Created March 19, 2024 10:26
Lines of code in Python, Lua, PHP and Ruby
=== Python-3.12.2 ===
github.com/AlDanial/cloc v 2.00 T=5.10 s (775.6 files/s, 446163.8 lines/s)
---------------------------------------------------------------------------------------
Language files blank comment code
---------------------------------------------------------------------------------------
Python 1946 136288 157620 635104
C 365 60311 57289 411210
C/C++ Header 492 21539 11893 206768
reStructuredText 490 85145 106460 102226
Text 133 2830 0 96064
@catwell
catwell / johnny-refiners.txt
Created December 14, 2023 15:44
Refiners dependency graph (all extras) w/ JohnnyDep
name summary
-------------------------------------------------- -------------------------------------------------------------------------------------------------------
refiners[conversion,test,training] The simplest way to train and run adapters on top of foundational models
├── bitsandbytes<0.42.0,>=0.41.0 k-bit optimizers and matrix multiplication routines.
├── datasets<3.0.0,>=2.14.0 HuggingFace community-driven open-source library of datasets
│ ├── aiohttp Async http client/server framework (asyncio)
│ │ ├── aiosignal>=1.1.2 aiosignal: a list of registered asynchronous callbacks
│ │ │ └── frozenlist>=1.1.0 A list-like structure which implements collections.abc.MutableSequence
│ │ ├── attrs>=17.3.0 Classes Without Boilerplate
│ │ ├── frozenlist>=1.1.1 A list
@catwell
catwell / bearer-seg.log
Created March 7, 2023 13:44
Bearer segfault
[bearer_1.0.0_linux_amd64 14:43] ./bearer scan bear-publishing
Loading rules
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x1d93a0 pc=0x7fc16c092f16]
runtime stack:
runtime.throw({0x1520dac?, 0x352?})
/opt/hostedtoolcache/go/1.19.6/x64/src/runtime/panic.go:1047 +0x5d fp=0x7fc16d518fc8 sp=0x7fc16d518f98 pc=0x43c55d
runtime.sigpanic()
/opt/hostedtoolcache/go/1.19.6/x64/src/runtime/signal_unix.go:819 +0x369 fp=0x7fc16d519018 sp=0x7fc16d518fc8 pc=0x452189
@catwell
catwell / 2022-11-27.rb
Created November 29, 2022 13:53
Binary tree serialization 😈
# Evil answer, don't try this at home 😈
def serialize(node, inbuf = nil)
buf = inbuf || StringIO.new
buf.write('Node.new(')
buf.write(node.val.inspect)
if node.left
buf.write(', ')
serialize(node.left, buf)
if node.right
@catwell
catwell / 2022-11-26.rb
Created November 28, 2022 13:51
smlpth daily 2022-11-26
def efficient_part2(input)
n = input.length
r = Array.new(n, 1)
p_up, p_down = 1, 1
0.upto(n - 1) do |i|
j = n - i - 1
r[i] *= p_up
r[j] *= p_down
p_up *= input[i]
p_down *= input[j]
@catwell
catwell / multipart.lua
Created November 9, 2022 09:12
Helping nodecentral with multipart post
-- see https://github.com/catwell/lua-multipart-post/issues/8#issuecomment-1307934583
-- fixed version (see diff)
local http = require("socket.http")
local ltn12 = require("ltn12")
local lfs = require "lfs"
http.TIMEOUT = 5
local function upload_file ( url, filename )
local fileHandle = io.open( filename,"rb")
@catwell
catwell / plnutil.d.tl
Created October 12, 2022 08:37
Pallene routines used in a backpropagation algorithm in Teal
local record plnutil
vec_zeros: function(integer): {number}
mat_zeros: function(integer, integer): {{number}}
mat_vec_mul: function({{number}}, {number}): {number}
mat_t_vec_mul: function({{number}}, {number}): {number}
vec_vec_2d_mul: function({number}, {number}): {{number}}
vec_pointwise_mul: function({number}, {number}): {number}
vec_add_inplace: function({number}, {number}, number)
mat_add_inplace: function({{number}}, {{number}}, number)
vec_clip_inplace: function({number},number, number)