Skip to content

Instantly share code, notes, and snippets.

View mrnugget's full-sized avatar

Thorsten Ball mrnugget

View GitHub Profile
use anyhow::Result;
use std::convert::Infallible;
use warp::Filter;
struct Deferred<T: FnOnce()> {
task: Option<T>,
}
impl<T: FnOnce()> Deferred<T> {
fn abort(&mut self) {
{
"name": "Snazzy",
"appearance": "dark",
"style": {
"background.appearance": "opaque",
"border": "#1d2433",
"border.variant": "#1d2433",
"border.focused": "#8695b777",
"border.selected": "#1d2433",
"border.transparent": "#1d2433",
@mrnugget
mrnugget / main.go
Created February 22, 2024 16:11
Why?
package main
import (
"fmt"
"log"
"os/exec"
"time"
)
func main() {
@mrnugget
mrnugget / buy-my-starlabs-starbook.md
Last active January 10, 2024 14:36
I'm selling my Star Labs Starbook. Who wants to buy it?

Buy my Star Labs Starbook 14-inch

Short version: I'm selling my Star Labs Starbook. I'm just not using it enough.

Specs

  • Model: Star Labs Starbook 14-inch
  • OS: Ubuntu (I'll wipe and reinstall Ubuntu)
  • CPU: 2.10GHz 12-core Intel i7-1260P, Turbo Boost up to 4.70GHz
  • RAM: 32GB 3200MHz DDR4
@mrnugget
mrnugget / main.c
Last active October 30, 2023 06:12
GTK4: focus leaving last-focused-child in GtkNotebook and then back into it
// Compile with:
// gcc $(pkg-config --cflags gtk4) -o main ./main.c $(pkg-config --libs gtk4) && ./main
//
// Run with:
// ./main
//
// Reproduce issue:
//
// 1. Click on Page 2
// 2. Select "view3" and type something.
@mrnugget
mrnugget / ContentView.swift
Created July 1, 2023 11:05
macOS Swift app with "Quit?" dialog that should accept return, but doesn't
import SwiftUI
struct ContentView: View {
@EnvironmentObject private var appDelegate: AppDelegate
var body: some View {
let confirmQuitting = Binding<Bool>(get: {
self.appDelegate.confirmQuit
}, set: {
use std::{
alloc::{self, Layout},
mem::size_of,
};
use crate::{
heap::{AllocError, AllocResult},
object::ObjectHeader,
raw::RawPtr,
};
@mrnugget
mrnugget / gc_resources.md
Created February 26, 2023 12:11
Resources I used so far (26 feb 2023) to build a GC for my toy compiler
[gchb]: https://gchandbook.org/
[clawing]: https://blog.mozilla.org/javascript/2013/07/18/clawing-our-way-back-to-precision/
[gsgc]: https://piumarta.com/software/gsgc/index.shtml
[migc]: https://github.com/playXE/migc
[yarpenruntime]: https://github.com/mdlugajczyk/yarpen/blob/master/runtime/yarpen_runtime.c
[bdwgc]: https://www.hboehm.info/gc/
[bdwgcslides]: https://www.hboehm.info/gc/04tutorial.pdf
[bdwdescr]: https://hboehm.info/gc/gcdescr.html
[writinginterpretersinrust]: https://rust-hosted-langs.github.io/book/introduction.html
[gcandrustpart0]: http://blog.pnkfx.org/blog/2015/10/27/gc-and-rust-part-0-how-does-gc-work/
@mrnugget
mrnugget / a.md
Created December 21, 2022 05:53
When I call my Rust function directly from C the top call frame disappears from the stack. Why?

Compile and run both files with (on Linux x86):

rustc --crate-type=staticlib gc_experiment4.rs && \
   gcc -O0 -g -o gc_experiment4 gc_experiment4.c -lgc_experiment4 -L. && \
  ./gc_experiment4

This will output the following:

@mrnugget
mrnugget / a.md
Last active November 20, 2022 11:03

UPDATE: See "Update" below

Problem

What can cause unaligned pointers to end up on my stack? Or: what, on my stack, can look like unaligned pointers?

Context is that I'm trying to write a conservative GC. I want to scan the stack for things that look like pointers (and then mark them, but I'm not at that point yet). I copied & hacked together some code from other GCs I found, which essentially does the following:

  1. At program start: save the current %rbp away as the "stack bottom" (highest address)
  2. When scanning stack: save now-current %rbp away as "stack top" (lowest address)