Skip to content

Instantly share code, notes, and snippets.

View berkus's full-sized avatar
🎯
Haptic drift

Berkus Decker berkus

🎯
Haptic drift
View GitHub Profile
@Hirrolot
Hirrolot / a-preface.md
Last active April 18, 2024 16:50
A complete implementation of the positive supercompiler from "A Roadmap to Metacomputation by Supercompilation" by Gluck & Sorensen

Supercompilation is a deep program transformation technique due to V. F. Turchin, a prominent computer scientist, cybernetician, physicist, and Soviet dissident. He described the concept as follows [^supercompiler-concept]:

A supercompiler is a program transformer of a certain type. The usual way of thinking about program transformation is in terms of some set of rules which preserve the functional meaning of the program, and a step-by-step application of these rules to the initial program. ... The concept of a supercompiler is a product of cybernetic thinking. A program is seen as a machine. To make sense of it, one must observe its operation. So a supercompiler does not transform the program by steps; it controls and observes (SUPERvises) the running of the machine that is represented by the program; let us call this machine M1. In observing the operation of

C++ spans: {*data,size} or {*b,*e} ?

Once Go has shown us the power of slices, there is no doubt that std::span was a very serious omittance in the original C++. Frankly, good old C codebases used the pointer+length metafor so often, it is difficult to explain why C++ got the construct this late. Probably, its designers considered non-owning pointers too rough or maybe too dangerous? An attempt to introduce a similar concept of std::string_view was clearly a failure and it was deprecated. At last, std::span is very widely recommended.

@slimsag
slimsag / ramblings.md
Last active December 13, 2023 08:02
Because cross-compiling binaries for Windows is easier than building natively

Because cross-compiling binaries for Windows is easier than building natively

I want Microsoft to do better, want Windows to be a decent development platform-and yet, I constantly see Microsoft playing the open source game: advertising how open-source and developer friendly they are - only to crush developers under the heel of the corporate behemoth's boot.

The people who work at Microsoft are amazing, kind, talented individuals. This is aimed at the company's leadership, who I feel has on many occassions crushed myself and other developers under. It's a plea for help.

The source of truth for the 'open source' C#, C++, Rust, and other Windows SDKs is proprietary

You probably haven't heard of it before, but if you've ever used win32 API bindings in C#, C++, Rust, or other languages, odds are they were generated from a repository called microsoft/win32metadata.

@urish
urish / raspberrypi4-native.cfg
Created November 4, 2021 01:43
OpenOCD Configuration for Raspberry Pi 4
interface bcm2835gpio
bcm2835gpio_peripheral_base 0xFE000000
# Transition delay calculation: SPEED_COEFF/khz - SPEED_OFFSET
# These depend on system clock, calibrated for stock 700MHz
# bcm2835gpio_speed SPEED_COEFF SPEED_OFFSET
bcm2835gpio_speed_coeffs 236181 60
# Each of the JTAG lines need a gpio number set: tck tms tdi tdo
diff --git a/emsdk.py b/emsdk.py
index 6d30c56..e2010bc 100644
--- a/emsdk.py
+++ b/emsdk.py
@@ -1241,12 +1241,12 @@ def find_latest_installed_tool(name):
# npm install in Emscripten root directory
def emscripten_npm_install(tool, directory):
- node_tool = find_latest_installed_tool('node')
- if not node_tool:
@LAK132
LAK132 / Makefile
Last active March 8, 2023 14:00
C++ embedded in a Makefile
#if 0
.PHONY: run
run: out.elf
./out.elf
out.elf: Makefile
g++ -o $@ -x c++ $^
ifeq (0, 1)
#endif
#include <stdio.h>
int main()
@skoe
skoe / ld.x
Last active September 12, 2022 18:32
Pure Rust Start-Up Code - Attempt 2
Add this to the linker script:
.text :
{
. = ALIGN(4);
/* Let the linker do the pointer arithmetic. The following values must
* have the same layout as struct MemInfo in the Rust init
* implementation. It must only contain FFI-safe types. For `LONG` refer
* to the GNU ld manual which is referenced by the LLVM lld manual:
* https://sourceware.org/binutils/docs/ld/Output-Section-Data.html
@mexus
mexus / arc_benchmark.rs
Created July 15, 2020 16:57
`Arc::clone` performance
use criterion::{criterion_group, criterion_main, Criterion};
use std::sync::Arc;
fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("arc", |b| {
let arc = Arc::new(String::from("Some string"));
b.iter(|| {
let clone = Arc::clone(&arc);
clone
})
import SwiftUI
import UIKit
protocol ASTextFieldDelegate {
func didBeginEditing(textField : UITextField)
func didEndEditing(textField : UITextField)
func didLeftItemtapped(_ button : UIButton)
}
use std::{
borrow::{Borrow, ToOwned},
marker::PhantomData,
ops::{Deref, Drop},
ptr::{self, NonNull},
};
pub unsafe trait Cursed<T: ?Sized>: Borrow<T> + Sized {
fn borrowed(borowed: &T) -> Option<NonNull<T>>;
fn owned(self) -> Option<NonNull<T>>;