Skip to content

Instantly share code, notes, and snippets.

Avatar
👾

Thom Chiovoloni thomcc

👾
View GitHub Profile
@thomcc
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>
View tinyxmlparser.cc
#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
View dot_perf_tests.rs
#![feature(test)]
#![recursion_limit = "1024"]
#![allow(dead_code)]
#![feature(stdsimd)]
extern crate test;
extern crate rand;
// Defines a little benchmarking DSL macro. If you've been linked here, it's safe to ignore.
#[macro_use]
View shape.rs
#[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};
View simd_match.rs
/// ```
/// # #[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(),
View radixsort.rs
#[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 {
#[inline]
@thomcc
thomcc / resolve_version.sh
Created Apr 2, 2021
bash function to resolve a crate version in a terrible way
View resolve_version.sh
# 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 `docs.rs/$1` and dump the redirected URL.
# We expect this to go to `docs.rs/crate/$crate/$version`
# or `docs.rs/$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.
#
View bad_xml.rs
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)>,