This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | |
pub fn concat(v: Vec<Vec<u32>>) -> Vec<u32> { | |
v.concat() | |
} | |
pub fn iter_flatten_collect(v: Vec<Vec<u32>>) -> Vec<u32> { | |
v.into_iter().flatten().collect() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// creates a nested tuple from the given args | |
/// ``` | |
/// assert_eq!( | |
/// vararg!("a", 15, true, 10.0), | |
/// ("a", (15, (true, (10.0, ())))) | |
/// ) | |
macro_rules! vararg { | |
($first:expr $(, $rest:expr)* $(,)?) => { | |
($first, vararg!( $($rest),* ) ) | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[cfg(test)] | |
mod tests { | |
use std::{ | |
sync::{ | |
atomic::{AtomicUsize, Ordering}, | |
Arc, | |
}, | |
time::Duration, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// # Exmaple | |
/// ``` | |
/// select! { | |
/// { $($yes)? } { if_present() } { if_absent() } | |
/// } | |
macro_rules! select { | |
({ $($_:tt)+ } { $($keep:tt)* } { $($discard:tt)* } ) => { $($keep)* }; | |
({} { $($discard:tt)* } { $($keep:tt)* } ) => { $($keep)* }; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{ | |
sync::mpsc, | |
time::{Duration, Instant}, | |
}; | |
/// Warns on any function that is behaving slow | |
/// | |
/// Useful for when your code appears to be getting stuck somewhere | |
/// and you want a fast "debug print" way of knowing where. | |
#[inline] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const QUANT: f32 = u16::MAX as f32; | |
struct CPoint(u16); | |
impl From<f32> for CPoint { | |
fn from(f: f32) -> Self { | |
assert!((0.0..=1.0).contains(&f), "given float {f} out of bounds"); | |
CPoint((f * QUANT) as u16) | |
} | |
} | |
impl From<CPoint> for f32 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Would it be bad if someone figured out how to manipulate the hash function to get a certain result? | |
Would it be bad if someone found out the input from the hash? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SCRIPT_NAME="$(basename "$0")" | |
AUDIO_INTERFACE_NAME="Scarlett Solo USB" # Discover name with command `arecord -l` | |
AUDIO_INTERFACE_DETAILS=$(arecord -l | grep "${AUDIO_INTERFACE_NAME}") | |
AUDIO_CARD=$(echo "${AUDIO_INTERFACE_DETAILS}" | grep -o -E 'card [0-9]+:' | tr -dc '0-9') | |
AUDIO_DEVICE=$(echo "${AUDIO_INTERFACE_DETAILS}" | grep -o -E 'device [0-9]+:' | tr -dc '0-9') | |
AUDIO_BUFFER_SIZE="2048" # The lower the number, the less latency introduced, but more likely buffer overruns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let y = "y̆"; | |
let mut chars = y.chars(); | |
assert_eq!(Some('y'), chars.next()); // not 'y̆' | |
assert_eq!(Some('\u{0306}'), chars.next()); | |
// INTERESTING: chars is unicode compatible, it just gives you code points in between your graphemes | |
for c in y.chars() { | |
println!("{}", c.is_lowercase()); // true, false | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(dead_code)] | |
//! https://www.kernel.org/doc/html/v4.17/media/uapi/v4l/pixfmt-yuyv.html | |
//! | |
//! V4L2_PIX_FMT_YUYV — Packed format with ½ horizontal chroma resolution, also known as YUV 4:2:2 | |
//! Description | |
//! | |
//! In this format each four bytes is two pixels. Each four bytes is two Y's, a Cb and a Cr. Each Y goes to one of the pixels, and the Cb and Cr belong to both pixels. As you can see, the Cr and Cb components have half the horizontal resolution of the Y component. V4L2_PIX_FMT_YUYV is known in the Windows environment as YUY2. | |
//! | |
//! Example 2.19. V4L2_PIX_FMT_YUYV 4 × 4 pixel image |
NewerOlder