Skip to content

Instantly share code, notes, and snippets.

Avatar
🎉
Celebrating 20 years of building open source tools

Karsten Schmidt postspectacular

🎉
Celebrating 20 years of building open source tools
View GitHub Profile
View walk-dir.zig
const std = @import("std");
const fs = std.fs;
const log = std.log;
const os = std.os;
fn walk(dir: fs.Dir) anyerror!void {
var it = dir.iterate();
loop: {
while (it.next()) |entry| {
if (entry) |e| {
@lithdew
lithdew / sparse.zig
Created June 26, 2022 09:26
zig: generational paged sparse set
View sparse.zig
const std = @import("std");
const sparse = @This();
/// This is an implementation of a paged sparse set that stores the payload in
/// the sparse array.
//
/// A sparse set has a dense and a sparse array. The sparse array is directly
/// indexed by a 64 bit identifier. The sparse element is linked with a dense
/// element, which allows for liveliness checking. The liveliness check itself
@mitchellh
mitchellh / Atlas.zig
Last active December 22, 2022 01:57
Bin-packed texture atlas implementation in Zig. https://en.wikipedia.org/wiki/Texture_atlas
View Atlas.zig
//! Implements a texture atlas (https://en.wikipedia.org/wiki/Texture_atlas).
//!
//! The implementation is based on "A Thousand Ways to Pack the Bin - A
//! Practical Approach to Two-Dimensional Rectangle Bin Packing" by Jukka
//! Jylänki. This specific implementation is based heavily on
//! Nicolas P. Rougier's freetype-gl project as well as Jukka's C++
//! implementation: https://github.com/juj/RectangleBinPack
//!
//! Limitations that are easy to fix, but I didn't need them:
//!
@reillyeon
reillyeon / async_function_return.md
Last active February 22, 2022 16:05
When does an async function return?
View async_function_return.md

When does an async function return?

Someone recently asked me when an async function in JavaScript "returns". This is an interesting question because while a function like f() below has a return statement in it, f() actually returns much earlier than that. To understand how this works, let's take a look at an example function. Here, a() and c() are normal synchronous functions and b() is another asynchronous function.

async function f() {
  a();
  await b();
  return c();
}
View about.md
View contract.py
import smartpy as sp
class SpectrumColors(sp.Contract):
def __init__(self):
self.init(
# fixed dimensions of the board
columns = 16,
rows = 16,
# limit to the total number of colors possible
max_colors = 12,
View parser.zig
const std = @import("std");
const Allocator = std.mem.Allocator;
pub const Error = error{
EndOfStream,
Utf8InvalidStartByte,
} || std.fs.File.ReadError || std.fs.File.SeekError || std.mem.Allocator.Error;
pub fn Parser(comptime Value: type, comptime Reader: type) type {
return struct {
@AssortedFantasy
AssortedFantasy / ndarray.zig
Last active November 26, 2021 20:59
A minimal implementation of higher dimensional slices in Zig.
View ndarray.zig
// Multi Dimensional Slices in Zig
// Sort of akin to ndarrays in Python's numpy
const std = @import("std");
const runtime_safety = std.debug.runtime_safety;
const mem = std.mem;
const NDSliceErrors = error{
InsufficientBufferSize,
ZeroLengthDimensionsNotSupported,
@memononen
memononen / biasgaininf.c
Last active February 2, 2022 10:09
bias gain inflection point
View biasgaininf.c
float evalCurve(float x, float tx, float ty, float sa, float sb)
{
const float EPS = 1e-6f;
if (x < tx) {
return (ty * x) / (x + sa * (tx - x) + EPS);
} else {
return ((1-ty) * (x-1)) / ((1-x) - sb * (tx - x) + EPS) + 1.0f;
}
}
@IanColdwater
IanColdwater / twittermute.txt
Last active March 29, 2023 14:08
Here are some terms to mute on Twitter to clean your timeline up a bit.
View twittermute.txt
Mute these words in your settings here: https://twitter.com/settings/muted_keywords
ActivityTweet
generic_activity_highlights
generic_activity_momentsbreaking
RankedOrganicTweet
suggest_activity
suggest_activity_feed
suggest_activity_highlights
suggest_activity_tweet