Skip to content

Instantly share code, notes, and snippets.

View ptruser's full-sized avatar
🍉
Melon

ptruser ptruser

🍉
Melon
View GitHub Profile
@DougGregor
DougGregor / macros.md
Last active October 24, 2023 16:42
A possible vision for macros in Swift

A Possible Vision for Macros in Swift

As Swift evolves, it gains new language features and capabilities. There are different categories of features: some fill in gaps, taking existing syntax that is not permitted and giving it a semantics that fit well with the existing language, with features like conditional conformance or allowing existential values for protocols with Self or associated type requirements. Others introduce new capabilities or paradigms to the language, such as the addition of concurrency or comprehensive reflection.

There is another large category of language features that provide syntactic sugar to eliminate common boilerplate, taking something that can be written out in long-form and making it more concise. Such features don't technically add any expressive power to the language, because you can always write the long-form version, but their effect can be transformational if it enables use cases that would otherwise have been unwieldy. The synthesis of Codable conformances, for ex

@mrdoob
mrdoob / WebAudio.js
Last active February 14, 2024 05:02
HTMLAudioElement polyfill using the WebAudio API with seamless loop support in Safari.
/**
* @author mrdoob / http://mrdoob.com/
*/
function WebAudio( context ) {
if ( context === undefined ) {
context = WebAudio.context;
@dreamsmasher
dreamsmasher / overload.rs
Created October 2, 2022 00:16
Function Overloading in Rust
#![feature(fn_traits, unboxed_closures)]
macro_rules! orelse {
(($($lhs:tt)+), $rhs:tt) => {$($lhs)+};
((), ($($rhs:tt)*)) => {$($rhs)*}
}
macro_rules! overload {
(
$v:vis fn $fn_name:ident {
@bramus
bramus / windows-viewports.md
Last active October 17, 2022 03:46
Interop 2022 Viewport Investigation: Behavior on a Windows Touch Screen Device

Windows On-Screen Keyboard vs. Viewports

Setup / General

  • Device: Dell XPS 13 9380 with Windows 10 Enterprise (19044.1949)
  • I had to enable a few things before I could trigger the OSK / show the button in the task bar
    • Don't recall which ones though :-/
  • Windows has various concepts for the OSK. If you hit CTRL+WIN+O for example a totally different OSK - one that floats and cannot be docked - pops up

The Good

@JarkkoPFC
JarkkoPFC / bitonic_sort64.h
Last active December 3, 2024 22:23
Bitonic sort for 64 elements
template<typename T>
void bitonic_sort64(T vals_[64])
{
int h=-1;
do
{
for(unsigned i=0; i<32; ++i)
{
unsigned idx0=2*i;
unsigned idx1=4*(i&h)-2*(i+h)-1;
@mattdesl
mattdesl / cli.js
Created September 13, 2022 10:37
colour palette from text prompt using Stable Diffusion https://twitter.com/mattdesl/status/1569457645182152705
/**
* General-purpose NodeJS CLI/API wrapping the Stable-Diffusion python scripts.
*
* Note that this uses an older fork of stable-diffusion
* with the 'txt2img.py' script, and that script was modified to
* support the --outfile command.
*/
var { spawn, exec } = require("child_process");
var path = require("path");
@steveruizok
steveruizok / cache.ts
Last active May 8, 2025 03:01
weak map gist
export class Cache<T extends object, K> {
items = new WeakMap<T, K>()
get<P extends T>(item: P, cb: (item: P) => K) {
if (!this.items.has(item)) {
this.items.set(item, cb(item))
}
return this.items.get(item)!
}
name: Update target browsers
on:
schedule:
- cron: "0 2 1 * *"
permissions:
contents: write
pull-requests: write
jobs:
update-browserslist-database:
runs-on: ubuntu-latest
@belm0
belm0 / article_sc_and_lua_1.md
Last active July 29, 2025 15:40
Structured concurrency and Lua (part 1)

Structured concurrency and Lua (part 1)

John Belmonte, 2022-Sep

I've started writing a toy structured concurrency implementation for the Lua programming language. Some motivations:

  • use it as a simple introduction to structured concurrency from the perspective of Lua (this article)
  • learn the fundamental properties of structured concurrency and how to implement them
  • share code that could become the starting point for a real Lua library and framework

So what is structured concurrency? For now, I'll just say that it's a programming paradigm that makes managing concurrency (arguably the hardest problem of computer science) an order of magnitude easier in many contexts. It achieves this in ways that seem subtle to us—clearly so, since its utility didn't reach critical mass until around 2018[^sc_birth] (just as control structures like functions, if, and while weren't introduced to languages until long after the first compu

@GavinRay97
GavinRay97 / Dockerfile
Created August 28, 2022 16:56
Hare Dockerized development environment
# Could also use FROM ubuntu/debian
ARG VARIANT="jammy"
FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT}
RUN set -x \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \