Skip to content

Instantly share code, notes, and snippets.

@dmbfm
dmbfm / kperf.zig
Last active December 13, 2021 04:07
Performance counters on apple M1 processors using Zig!
const std = @import("std");
// Sources:
// - https://github.com/lemire/Code-used-on-Daniel-Lemire-s-blog/blob/master/2021/03/24/m1cycles.cpp
// - https://gitea.com/matteyeux/darwin-xnu/src/branch/master/osfmk/kperf
// - https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210413004523.6500-1-josh@itanimul.li/
// - https://github.com/GMUCERG/PQC_NEON/blob/main/neon/kyber/m1cycles.c
const c = @cImport({
@cInclude("pthread.h");
@dmbfm
dmbfm / index.js
Last active April 22, 2021 17:10
Fanzy-zones configurator
#!/usr/bin/env node
const fs = require('fs');
const path = `${process.env.LocalAppData}\\Microsoft\\PowerToys\\FancyZones\\zones-settings.json`;
fs.copyFileSync(path, path + `.bk-${Date.now()}`);
let settings = require(path);
@dmbfm
dmbfm / ReadOnlyAttribute.cs
Created March 9, 2021 22:46 — forked from MattRix/ReadOnlyAttribute.cs
Read Only Attribute for Unity (just mark stuff as [ReadOnly] the same way you would use [HideInInspector])
using UnityEngine;
using System;
using System.Reflection;
using System.Text.RegularExpressions;
[AttributeUsage (AttributeTargets.Field,Inherited = true)]
public class ReadOnlyAttribute : PropertyAttribute {}
#if UNITY_EDITOR
[UnityEditor.CustomPropertyDrawer (typeof(ReadOnlyAttribute))]
package main
import (
"fmt"
"image"
"image/color"
"image/png"
"math"
"os"
)
@dmbfm
dmbfm / threshold.go
Created January 31, 2021 22:41
B/w thresholding of a png image using Go
package main
import (
"fmt"
"image"
"image/color"
"image/png"
"os"
)
@dmbfm
dmbfm / slice.c
Created December 19, 2020 03:27
Experiment on array slices in c, with optional bounds checking which can be turned off by the FAST macro.
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#define FAST
#define Slice(type) Slice_##type
#define make_slice_type(type) \
typedef struct Slice(type) {\
size_t len;\
@dmbfm
dmbfm / optional.c
Last active December 7, 2020 03:02
Playing around with the idea of Maybe/Option/Optional type in C using silly macros
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define maybe(type) maybe_##type
#define some(type, v) ((maybe(type)) { .is_something = 1, .value = v})
#define nothing(type) ((maybe(type)) { .is_something = 0 })
#define unwrap(x) (is_nothing(x) ? abort() : 0, x.value)
#define is_nothing(x) (x.is_something == 0)
#define ifsome(x) if (!is_nothing(x))
@dmbfm
dmbfm / Makefile
Created November 24, 2020 16:54 — forked from skeeto/README.md
AI driving simulation
.POSIX:
CC = cc
CFLAGS = -Ofast -fopenmp -g -Wall -Wextra
LDFLAGS =
LDLIBS = -lm
aidrivers: aidrivers.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ aidrivers.c $(LDLIBS)
clean: