Skip to content

Instantly share code, notes, and snippets.

View thomcc's full-sized avatar
🦀

Thom Chiovoloni thomcc

🦀
View GitHub Profile
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)>,
@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 / strip-json-comments.rs
Created November 4, 2019 20:35
strip-json-comments rust (untested, kept here so i can find it later)
pub fn strip_json_comments(s: &str) -> String {
let mut result = String::with_capacity(s.len());
let mut iter = s.chars();
while let Some(c) = iter.next() {
if c == '"' {
// It's a string, skip to end without touching any comments inside.
result.push(c);
while let Some(c) = iter.next() {
@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