Skip to content

Instantly share code, notes, and snippets.

View BartMassey's full-sized avatar

Bart Massey BartMassey

View GitHub Profile
@BartMassey
BartMassey / crate-release-checklist.md
Created November 17, 2021 19:14
Rust Crate Release Checklist

Crate Release Checklist

First published release

  • Add Rustdoc root to the crate root

      #![doc(html_root_url = "https://docs.rs/<crate>/<version>")]
    

    (where <crate> is the crate name and <version> is the version name)

@BartMassey
BartMassey / u256conv.rs
Created January 5, 2020 07:30
Various conversions for U256 values, done properly with minimal tests
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
pub struct U256([u8; 32]);
impl Into<u8> for U256 {
fn into(self) -> u8 {
for b in &self.0[0..31] {
assert_eq!(*b, 0);
}
self.0[31]
}
@BartMassey
BartMassey / tree.py
Created December 26, 2019 08:37
Prime Christmas Tree Generator
#!/usr/bin/python3
# Bart Massey
# Prime Christmas Tree printer, inspired by
# https://www.reddit.com/r/interestingasfuck/
# comments/efhy5m/i_found_this_really_great_the_correct_alignment/
# This code is licensed under the "MIT license". See
# https://opensource.org/licenses/MIT for license terms.
@BartMassey
BartMassey / good-appender.rs
Created October 8, 2019 21:32
Good Appender, not Great
// https://www.reddit.com/r/rust/comments/df12bs/roast_my_code_greatappender_repeatedly_append/
use std::convert::TryInto;
use std::fs::OpenOptions;
use std::io::Write;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
/// good-appender
fn main() {
use std::fmt::{self, Display, Formatter};
use std::io::{self, Write};
use tabwriter::TabWriter;
struct Table([[usize; 2]; 2]);
impl Display for Table {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let write_table = || -> io::Result<Vec<u8>> {
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::io::Read;
#[derive(Serialize, Deserialize)]
#[serde(rename_all="camelCase")]
struct Item {
transfer_status : u64,
dismantle_permission : u64,
// Copyright © 2019 Jeff Austin, Kamakshi Nagar
// [This program is licensed under the "MIT License"]
// Please see the file LICENSE in the source
// distribution of this software for license terms.
/*
citations:
Mark Morrissey --CS333 Operating Systems--Portland State University practice exams:
https://web.cecs.pdx.edu/~markem/CS333/exams/Final%202019-01.pdf
#![deny(unused)]
use std::io::{self, Read};
#[derive(PartialEq, Copy, Clone)]
enum Tile {
None,
Wall,
Goal,
}
@BartMassey
BartMassey / option.js
Last active July 26, 2019 21:37
"Option type" for Javascript
"use strict";
class Some {
constructor(value) {
this.value = value;
}
is_some(self) {
return true;
}
@BartMassey
BartMassey / scope.py
Last active May 26, 2019 09:02
Python scoping rules demo
a = 'a'
def f1():
global a
a = 'af1'
f1()
# prints af1
print(a)