Skip to content

Instantly share code, notes, and snippets.

View samsartor's full-sized avatar

Sam Sartor samsartor

View GitHub Profile
@samsartor
samsartor / lssafetensors.rs
Last active October 23, 2024 20:44
view the contents of a safetensors file
#!/usr/bin/env -S cargo +nightly -Zscript
---cargo
[package]
edition="2021"
[dependencies]
clap = { version = "4.2", features = ["derive"] }
safetensors = "0.4.2"
colored = "2.0"
regex = "1.5"
import Browser
import Html exposing (Html, Attribute, div, input, text, button)
import Html.Attributes exposing (..)
import Html.Events exposing (onInput, onClick)
import Dict exposing (Dict)
main =
Browser.sandbox { init = init, update = update, view = view }
@samsartor
samsartor / sde-demo.jl
Created November 8, 2021 14:32
SDE Demo
### A Pluto.jl notebook ###
# v0.16.1
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local el = $(esc(element))
@samsartor
samsartor / pins.md
Last active October 14, 2021 20:36
First-Class Pin Stuff

Goal #1: safe pin projection

It should be possible to safely project through pinned user types:

struct Data<F: Future> {
    future: F,
    output: Option<F::Output>,
}

impl<F: Future> Data<F> {
@samsartor
samsartor / bithack.rs
Created January 31, 2019 14:57
Connect-Four Bithacking
#![allow(dead_code)]
const L_COL: u64 = 0xFF00000000000000;
const R_COL: u64 = 0x00000000000000FF;
const B_ROW: u64 = 0x0101010101010101;
const T_ROW: u64 = 0x8080808080808080;
const B_ROWS: u64 = !T_ROW;
const R_COLS: u64 = !L_COL;
@samsartor
samsartor / linear_solitaire.hs
Created January 31, 2018 16:29
Plays the "linear" version of Solitaire
type Card = (Int, Int)
type Deck = [Card]
type Hand = [Card]
collase_one :: Hand -> Hand
collase_one ((_, ra) : _ : _ : (_, rb) : rest) | ra == rb = rest
collase_one (a@(sa, _) : _ : _ : b@(sb, _) : rest) | sa == sb = [a, b] ++ rest
collase_one t = t
collape_all :: Hand -> Hand
@samsartor
samsartor / amicable.rs
Created June 29, 2017 19:07
Project Euler #95 (Rust)
use std::cmp::min;
use std::usize::MAX as NUM_MAX;
const MAX: usize = 1000000;
fn main() {
// statically-allocated list used by `amicable` to mark numbers
let mut marks = [0; MAX + 1];
let (min, len) = (1..marks.len())
.flat_map(|n| amicable(n, &mut marks)) // flat map to ignore `None`s
@samsartor
samsartor / two_buttons.rs
Last active June 11, 2017 01:19
A theoretical boxflight double-button example
pub fn main() {
let mut ctx = Context::new();
let mut rng = thread_rng();
ctx.add_element(ButtonsModel {
color_a: random_color(&mut rng),
color_b: random_color(&mut rng),
});
ctx.launch();
}
@samsartor
samsartor / ElytraModel.java
Last active August 1, 2024 20:02
Code for simulating the elytra item in Minecraft
/**
* An accurate simulation of the elytra item as of Minecraft 15w41b
*/
public class ElytraModel
{
public int glideTime;
public int damageTaken;
public double posX;
public double posY;
@samsartor
samsartor / plexisphere.js
Last active August 29, 2015 14:26
Create n-dimentional plexispheres!
(function() {
var arr = function(length, fill) {
var arr = [];
for (var i = 0; i < length; i++)
{
arr.push(fill);
}
return arr;
};