Skip to content

Instantly share code, notes, and snippets.


Thom Chiovoloni thomcc

View GitHub Profile
thomcc / min_max.hh
Created Dec 1, 2013
C++11 variadic max, min, and minmax implementations.
View min_max.hh
#pragma once
#include <utility>
// varidic max, min, and minmax implementation (named maximum, minimum and min_max to avoid confusion)
// no support for custom comparators (mainly because i'm not sure how they should be specified)
namespace detail {
// max base case
template <class T>
#include <string>
#include <vector>
#include <cstddef>
#include <memory>
#include <iostream>
#include <cassert>
#include <stdexcept>
struct XmlNode {
struct Attribute {
View coord.ts
// Coord is a way of storing a 2d integer vector (e.g. vec2i or similar) as a
// value type by packing it into a number. It will do what you want in a Map or
// Set, you can compare them for equality, and it should be free of alloctions
// (at least in Spidermonkey and V8, but probably anywhere else too).
// The downside is that it's a pain to debug, use, and it has ugly syntax. It's
// type safe (in typescript) tho.
// Each component is stored as a 15 bit (signed, 2's complement) integer. These
#![recursion_limit = "1024"]
extern crate test;
extern crate rand;
// Defines a little benchmarking DSL macro. If you've been linked here, it's safe to ignore.
#[derive(Debug, Clone, Default)]
pub struct Shape {
pub vertices: Vec<V3>,
pub tris: Vec<[u16; 3]>,
impl Shape {
// ...
pub fn new_sphere(radius: f32, bands: (usize, usize)) -> Self {
use std::{f32, u16};
/// ```
/// # #[allow(dead_code)] fn code_requiring_fma_and_avx() {}
/// # #[allow(dead_code)] fn code_requiring_sse41() {}
/// # #[allow(dead_code)] fn code_requiring_sse2() {}
/// # #[allow(dead_code)] fn fallback_code() {}
/// # fn main() {
/// let thing = t3m::simd_match! {
/// // Comma separate required target features to require both.
/// "fma", "avx" => code_requiring_fma_and_avx(),
/// "sse4.1" => code_requiring_sse41(),
#[derive(Default, Debug, Clone)]
pub struct RadixSorter {
// TODO: only need one buffer.
unsorted_buf: Vec<(usize, u32)>,
pub sorted_buf: Vec<(usize, u32)>,
impl RadixSorter {
thomcc /
Created Apr 2, 2021
bash function to resolve a crate version in a terrible way
# helper fn that returns version number given $crate or $crate/$semver.
# both must be url-encoded but the / must be a / if provided.
# doesn't handle cases where the version/crate/whatever doesn't exist.
resolve_version() {
# Perform `HEAD` request to `$1` and dump the redirected URL.
# We expect this to go to `$crate/$version`
# or `$crate/$version/$crate/` depending on if the crate has
# docs or idrk. Maybe a couple other urls are possible, it
# took a bit of testing for the `sed` script to handle all cases I found.
use std::string::String;
use std::str::Chars;
use std::iter::{Enumerate, Peekable};
// an xml parser that's decent enough if you don't care about parsing perf
// and you completely control the input.
#[derive(Clone, Debug)]
pub struct XmlNode {
pub tag: String,
pub attributes: Vec<(String, String)>,