Skip to content

Instantly share code, notes, and snippets.

View thomcc's full-sized avatar
🦀

Thom Chiovoloni thomcc

🦀
View GitHub Profile
//! This is a (hopefully) correct implementation of a lockfree stack.
//!
//! Doing this without a memory reclamation implementation requires pointer
//! tagging, which is slightly architecture specific. This supports aarch64 and
//! x86_64 so long as 5-level page tables aren't in use (rare to the point of
//! nonexistence), and arm64e (or other hardware pointer authentication) is not
//! enabled, which is not currently supported by Rust. On x86_64/aarch64 where
//! this doesn't hold, it will panic.
//!
//! That said, while this implementation is believed to be correct, it could
@thomcc
thomcc / gist:d23fbed230f5e06d91409f31a2fc9985
Created November 5, 2020 10:55 — forked from rygorous/gist:2203834
float->sRGB8 using SSE2 (and a table)
// float->sRGB8 conversions - two variants.
// by Fabian "ryg" Giesen
//
// I hereby place this code in the public domain.
//
// Both variants come with absolute error bounds and a reversibility and monotonicity
// guarantee (see test driver code below). They should pass D3D10 conformance testing
// (not that you can verify this, but still). They are verified against a clean reference
// implementation provided below, and the test driver checks all floats exhaustively.
//
@thomcc
thomcc / README.md
Last active October 7, 2020 01:26
github action runner target info
// https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=26888dbe066530c56f7181d3abc030e0
use std::borrow::Cow;
pub trait IntoUtf8Lossy {
type String;
fn into_utf8_lossy(self) -> Self::String;
}
impl<'a> IntoUtf8Lossy for &'a [u8] {
type String = Cow<'a, str>;
@thomcc
thomcc / prelude.rs
Created August 30, 2020 19:35
evcxr prelude
pub use std::{mem::*, ptr::NonNull, char};
pub use std::marker::PhantomData;
pub trait EvcxrNumFmtHelp {
fn hex(self) -> HexF;
fn bin(self) -> BinF;
}
impl<I: Into<i128>> EvcxrNumFmtHelp for I {
fn hex(self) -> HexF { HexF(self.into() as u128, core::mem::size_of::<I>()) }
fn bin(self) -> BinF { BinF(self.into() as u128, core::mem::size_of::<I>()) }
}
use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ValueRef};
#[derive(Debug, Clone, PartialEq)]
pub struct LossyString(pub String);
impl FromSql for LossyString {
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
if let ValueRef::Text(bytes) = value {
let fixed = String::from_utf8_lossy(bytes).to_string();
@thomcc
thomcc / lib.rs
Last active February 6, 2020 10:43
proc-macros for wrapping things with normal macros
extern crate proc_macro;
use proc_macro::{Delimiter, Group, TokenStream, TokenTree};
/// usage:
/// ```
/// #[wrap_with(my_macro!)]
/// pub struct Blah { ... }
/// ```
///
/// becomes

Remerge design

Caveat: These are fairly rough notes.

Some team in the future pulls in the remerge android component/xpcom component/jsm/etc, authors a schema and initializes a remerge database.

They insert/update records in the database, and these changes are all checked for validity versus the schema.

The schema provides:

  • The name of the collection.
@thomcc
thomcc / init.evcxr.rs
Created December 7, 2019 21:36
init.evcxr hex/binary printing "prelude"
// note: in my actual init.evcxr, this is all on one line, but I've rustfmted it for convenience
// the basic idea is that i just can call `some_expr_returning_integer.hex()` or
// `some_expr_returning_integer.bin()` to get a pretty-printed hex or binary version. zeroes are
// filled in, and every 4 or 8 (for hex/binary respectively) digits has a `_` separator.
// It works on anything that is Into<i128>. for things that aren't into<i128> but that
// i find myself needing to format, (specifically u128, f32, and f64), you need
// to do .hexx() or .binx(). this could be fixed but this file is a pain to maintain (it's one line)
// so... yeah.
// ```
// >> 30.hex()
@thomcc
thomcc / lib.rs
Created October 6, 2019 00:16
fexel_hull/src/lib.rs
#![no_std]
extern crate alloc;
use alloc::vec::Vec;
use fexel_num::{vec3x, X19, x19};
const ZERO: x19 = x19::from_bits(0);
const ONE: x19 = X19!(1.0);
/// The object that's used for computing the convex hull. This is basically a
/// bunch of scratch memory so that if you want to avoid allocating a bunch of