Skip to content

Instantly share code, notes, and snippets.

View sstadick's full-sized avatar

Seth sstadick

View GitHub Profile
#!/usr/bin/env bash
# Kill all open things except iTerm2
osascript \
-e 'tell application "System Events" to set quitapps to name of every application process whose background only is false and name is not "iTerm2"' \
-e 'repeat with appName in quitapps' \
-e 'try' \
-e 'quit application appName' \
-e 'end try' \
-e 'end repeat'; \
@sstadick
sstadick / rusty_iterator.mojo
Created September 19, 2025 15:18
Rust flavored iteration
trait RustyIterator(Copyable, Movable):
alias Element: Copyable & Movable
fn next(mut self) -> Optional[Self.Element]:
...
@fieldwise_init
struct OwningIterator(RustyIterator):
alias Element = Int
@sstadick
sstadick / ish_parasail_timings.txt
Last active July 21, 2025 23:33
ish and parasail timings
# Parasail commit: 600fb261 (v2.6.2)
# Ish commit: 5090c3e (v1.3.0)
# Capping parasail threads to 16, to match ish which can only use physical cores (mojo bug), so both use 16 threads
# SSE
time ./apps/parasail_aligner -a sg_striped_sse41_128_16 -X 2 -x -M 2 -o 3 -e 1 -d -t 1 -q ./patterns.fa -f /srv/refdata/chm13v2.0.fa -v -V
--> 1m21.371s
time ./apps/parasail_aligner -a sg_dx_striped_sse41_128_16 -X 2 -x -M 2 -o 3 -e 1 -d -t 1 -q ./patterns.fa -f /srv/refdata/chm13v2.0.fa -v -V
--> 1m20.438s
time ./apps/parasail_aligner -a sg_dx_striped_sse41_128_16 -X 2 -x -M 2 -o 3 -e 1 -d -t 16 -q ./patterns.fa -f /srv/refdata/chm13v2.0.fa -v -V
@sstadick
sstadick / read_delim.mojo
Last active July 3, 2025 10:43
Example reading a simple delimited file in Mojo.
"""Example usage of DelimReader on World Cities Pop.
Deps:
- pixi add extramojo (this example uses v0.15.0)
- mojo 25.4
Data:
- https://github.com/BurntSushi/rust-csv/blob/master/examples/data/bench/worldcitiespop.csv
- cat worldcitiespop.csv | cut -f6,7 -d, | tail -n +2 > lat_long.csv
@sstadick
sstadick / load_simd.mojo
Created May 9, 2025 17:47
UnsafePointer.load vs @parameter setting
@export
@no_inline
fn compare[
dtype: DType, width: Int
](
read lhs: List[Scalar[dtype]],
read rhs: List[Scalar[dtype]],
mut result: List[Scalar[dtype]],
):
@parameter
import math
from algorithm import vectorize
from benchmark import (
Bench,
Bencher,
BenchId,
BenchMetric,
ThroughputMeasure,
keep,
import math
from algorithm import vectorize
from bit import pop_count
from memory import pack_bits
from sys import simdwidthof
alias U8_SIMD_WIDTH = simdwidthof[DType.uint8]()
"""Get the HW SIMD register size for uint8"""
from memory import UnsafePointer
from os import abort
@value
struct TreeNode:
var data: String
var key: String
var hash: Int
var left: UnsafePointer[Self]
@sstadick
sstadick / monitor.sh
Created January 22, 2025 22:13
Monitor a Process Memory Usage
#!/bin/bash
set -eo pipefail
# redirect all stdout and stderr to a logfile AND display it on the terminal
exec &> >(tee -a monitor.log)
# pid: Process ID number
# x_pmem: Memory usage as percentage of total system memory (multiplied by 10 (unit conversion between rss and mem_tot))
# x_vsz: Virtual memory size in KB (allocated memory)
@sstadick
sstadick / splitmix64.rs
Created January 21, 2025 22:23
SplitMix64 Hasher for Rust u64
use std::hash::{BuildHasher, Hasher};
#[derive(Clone, Copy, Default)]
pub struct SplitMix64Hasher(u64);
impl Hasher for SplitMix64Hasher {
#[inline]
fn finish(&self) -> u64 {
self.0
}