Skip to content

Instantly share code, notes, and snippets.

View martinmroz's full-sized avatar

Martin Mroz martinmroz

  • San Francisco, CA
View GitHub Profile
@martinmroz
martinmroz / functional.rs
Created October 27, 2019 02:35
A functional take on generating a span over an entire byte string
/// Computes the flux over the provided input byte string.
fn flux_over_byte_string<T>(input: T) -> Option<Flux>
where
T: AsRef<[u8]> {
input.as_ref()
.iter()
.cloned()
.map(Flux::from)
.fold(None, |acc, next| span_opt(acc, Some(next)))
}
@martinmroz
martinmroz / rayon.rs
Created October 27, 2019 02:39
Parallelized version of our counter.
/// Computes the flux over the provided input byte string.
fn flux_over_byte_string<T>(input: T) -> Option<Flux>
where
T: AsRef<[u8]> {
input.as_ref()
.par_iter()
.cloned()
.map(Flux::from)
.fold(|| None, |acc, next| span_opt(acc, Some(next)))
.reduce(|| None, |acc, next| span_opt(acc, next))
@martinmroz
martinmroz / performance_3.csv
Created October 27, 2019 02:44
Final performance numbers.
file wc time wc mem wc_rs time wc_rs mem
empty.txt 0.00s 671kB 0.00s 786kB
big.txt 0.02s 1.72MB 0.01s 1.53MB
huge.txt 0.32s 1.72MB 0.16s 1.61MB
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_flux_over_byte_string() {
assert_eq!(
flux_over_byte_string("testing one two three".as_bytes()),
Some(Flux::new(CharType::NotSpace, 4, 0, CharType::NotSpace))
);
}
pub fn levenshtein_distance(source: &str, target: &str) -> usize {
if source.len() == 0 || target.len() == 0 {
return std::cmp::max(
source.chars().count(),
target.chars().count()
);
}
let source_chars: Vec<char> = source.chars().collect();
/*
* tube_display.c
* Project TubeClock/Display
*
* Created Friday, September 3, 2010 by Martin Mroz.
* Copyright (C) 2010 Martin Mroz, All Rights Reserved.
*/
#include <avr/pgmspace.h>
#include "hardware/tube_display.h"
@martinmroz
martinmroz / dump_memory_region.rs
Last active November 1, 2020 03:42
Dump MemoryRegion
struct MemoryRegion {
pub start: u32,
pub end: u32,
pub buffer: Vec<u8>,
pub name: String,
}
/// I32HEX supports record types:
/// - Data
/// Specifies up to 255 bytes of data.
@martinmroz
martinmroz / NSString+Bcbp.m
Created December 29, 2021 07:15
Rust -> NSString -> String Bridge
/*
* Copyright (C) 2019 Martin Mroz
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN