Skip to content

Instantly share code, notes, and snippets.

View shqld's full-sized avatar
🦭
shqld

shqld

🦭
shqld
View GitHub Profile
struct Context {
_inner: *mut std::ffi::c_void,
}
impl Drop for Context {
fn drop(&mut self) {
println!("drop: Context")
}
}
@shqld
shqld / main.rs
Created September 4, 2023 03:51
Rust generic function monomorphization optimization
#![allow(dead_code, unused_variables, clippy::from_over_into)]
struct Inner {
raw: *mut [u8; 0],
}
struct Object {
inner: Inner,
}
/**
* https://chromium.googlesource.com/chromium/src/third_party/WebKit/Source/devtools/+/eb375f3b31a67df908c93a827dd9e78d3212be60/front_end/product_registry_impl/sha1/sha1.js
*/
/*
* A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
* in FIPS 180-1
* Version 2.2 Copyright Paul Johnston 2000 - 2009.
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
* Distributed under the BSD License
@shqld
shqld / super-simple-atom.ts
Created August 15, 2022 14:30
Super simple state management system like Recoil
import { useState, useEffect } from "preact/hooks"
type Listener<T> = (state: T) => void
type Updater<T> = (state: T) => T
type Context<T> = {
setState(update: T | Updater<T>): void
subscribe(listener: Listener<T>): void
unsubscribe(listener: Listener<T>): void
getState(): T
}
@shqld
shqld / nominal_number_types.ts
Created April 7, 2022 11:44
Nominal Number types in TypeScript
class Flavoring<FlavorT> {
private _flavor?: FlavorT;
}
type Flavor<Base, Flavor> = Base & Flavoring<Flavor>;
type i32 = Flavor<number, 'i32'>
type i64 = Flavor<number, 'i64'>;
const a: i32 = 1
@shqld
shqld / compose.varnish-benchmark.yaml
Last active March 23, 2022 13:54
Benchmarking varnish sample
version: '3.8'
services:
varnish:
image: varnish:stable
volumes:
- type: bind
source: ./varnish
target: /etc/varnish
read_only: true
tmpfs: /var/lib/varnish:exec
@shqld
shqld / cargo_x86_64-unknown-linux-gnu-on-m1-mac.sh
Created March 15, 2022 14:19
cargo build for the target x86_64-unknown-linux-gnu on M1 Mac
# https://github.com/messense/homebrew-macos-cross-toolchains
brew tap messense/macos-cross-toolchains
brew install x86_64-unknown-linux-gnu
export CC_X86_64_UNKNOWN_LINUX_GNU=x86_64-unknown-linux-gnu-gcc
export CXX_X86_64_UNKNOWN_LINUX_GNU=x86_64-unknown-linux-gnu-g++
export AR_X86_64_UNKNOWN_LINUX_GNU=x86_64-unknown-linux-gnu-ar
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-unknown-linux-gnu-gcc
@shqld
shqld / cargo_build_for_alpine_linux.sh
Last active March 9, 2022 15:22
cargo build for alpine linux (`aarch64-unknown-linux-musl`) on M1 Mac
# https://github.com/messense/homebrew-macos-cross-toolchains
brew tap messense/macos-cross-toolchains
brew install aarch64-unknown-linux-musl
export CC_AARCH64_UNKNOWN_LINUX_MUSL=aarch64-unknown-linux-musl-gcc
export CXX_AARCH64_UNKNOWN_LINUX_MUSL=aarch64-unknown-linux-musl-g++
export AR_AARCH64_UNKNOWN_LINUX_MUSL=aarch64-unknown-linux-musl-ar
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-unknown-linux-musl-gcc
@shqld
shqld / help.Makefile
Last active February 2, 2022 15:25
'make help' for self-documenting Makefile
CUR := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
NULL := /dev/null
define touch
@mkdir -p $(@D); touch $(@)
endef
.DEFAULT_GOAL := help
help: ## Self-documented Makefile
@shqld
shqld / promises_are_not_correctly_handled_on_node_js_unlike_chrome.js
Last active January 7, 2022 03:01
Promises are not correctly handled on Node.js unlike Chrome
main()
async function main() {
const tasks = []
tasks.push(fail())
// Commenting out this line makes it work
await new Promise((resolve) => setTimeout(resolve, 0))