Skip to content

Instantly share code, notes, and snippets.

View lassade's full-sized avatar

Felipe Jorge lassade

View GitHub Profile
@lassade
lassade / fixed_swiss_hashmap.zig
Last active August 31, 2024 03:59
A fixed (no allocations) hashmap that follows the Google Swiss Table design principles
const std = @import("std");
const builtin = @import("builtin");
pub const StringContext = struct {
pub inline fn hash(_: @This(), s: []const u8) u64 {
return std.hash_map.hashString(s);
}
pub inline fn eql(_: @This(), a: []const u8, b: []const u8) bool {
return std.mem.eql(u8, a, b);
}
@lassade
lassade / slabAlloc.zig
Created July 17, 2024 19:27
allocates many slices with different sizes with a single allocation
pub fn SlabAllocation(comptime types: []const type) type {
var alignment: usize = 1;
var slices: [types.len]type = undefined;
for (types, 0..) |T, i| {
slices[i] = []T;
alignment = @max(alignment, @alignOf(T));
}
const out_alignment = alignment;
const Slices = std.meta.Tuple(&slices);
return struct {
@lassade
lassade / decode_hex.zig
Last active June 3, 2024 02:17
zig decodeHex SIMD
// compile with: -mcpu=x86_64+sse2 to ensure sse2 support
pub fn decodeHex(input: []const u8, output: []u8) !void {
const block_size = 16; // change block size to use avx2
const ByteBlock = @Vector(block_size, u8);
const IntBlock = @Vector(block_size / 4, u32);
if (input.len & 1 != 0) {
return error.OddLenghtInput;
}
@cmf028
cmf028 / aabb_transform.comp
Last active May 24, 2025 15:06
Optimized matrix transforms of an AABB to an AABB
// The MIT License (MIT)
// Copyright (c) 2018 cmf028
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
@slembcke
slembcke / CustomProjection.cs
Last active May 30, 2025 21:56
Custom projections for Unity2D games.
using UnityEngine;
using System.Collections;
// This script is meant to be attached to your main camera.
// If you want to use it on more than one camera at a time, it will require
// modifcations due to the Camera.on* delegates in OnEnable()/OnDisable().
[ExecuteInEditMode]
public class CustomProjection : MonoBehaviour {
private void OnEnable(){
@maxattack
maxattack / QuaternionUtil.cs
Last active July 24, 2025 16:54
Some Helper Methods for Quaternions in Unity3D
using UnityEngine;
/*
Copyright 2016 Max Kaufmann (max.kaufmann@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
@theredpea
theredpea / utf_8_encoding_for_url_encoding.py
Last active July 14, 2022 19:44
Understanding UTF-8 Encoding algorithm
# - - coding: utf-8 - -
# This class http://www.w3.org/International/URLUTF8Encoder.java
# In Python
# To understand how
# 新 ("xin", 1st tone, means "new" in Mandarin)
# U+65B0 (Unicode codepoint http://unicode-table.com/en/search/?q=%E6%96%B0)
# %E6%96%B0 (URL encoding in UTF-8 http://www.url-encode-decode.com/)
# Interesting: Not fixed-width! "新" not same size as "T"