Skip to content

Instantly share code, notes, and snippets.

View thomcc's full-sized avatar
🦀

Thom Chiovoloni thomcc

🦀
View GitHub Profile
static A: AtomicU8 = AtomicU8::new(0);
static B: AtomicU8 = AtomicU8::new(0);
const ORDER: Ordering = ???;
let writer_0 = thread::spawn(|| {
A.store(1, ORDER);
});
let writer_1 = thread::spawn(|| {
B.store(1, ORDER);
@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 / bad_xml.rs
Last active February 2, 2025 07:11
#[derive(Clone, Debug)]
pub struct XmlNode {
pub tag: String,
pub attributes: Vec<(String, String)>,
pub children: Vec<XmlNode>,
pub body: String,
}
impl XmlNode {
pub fn new(tag: String) -> XmlNode {
@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()