This file contains hidden or 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 | |
# This function adds an additional command to the trap stack. Each command | |
# added in this way will be called in reverse order when the signal is received. | |
# | |
# This function works with a simple concatenation with the currently existing | |
# trap function. Popping something from the trap stack without running it is | |
# left as an exercise to the reader; it requires at least a parser capable of | |
# matching { } correctly. | |
# |
This file contains hidden or 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
import {memoize} from "lodash" | |
/** | |
* Helper for passing a callback to each component in a loop. Given a callback | |
* with the signature (key, ..args), returns a new factory with the signature | |
* (key) => (...args). When called with a key, returns a wrapper function taking | |
* (...args) wich calls the original callback. This wrapper function is guaranteed | |
* to be the same for any given key. | |
* | |
* The callback must have NO dependencies that might change between renders. It |
This file contains hidden or 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
trait Truthy: Sized { | |
fn is_truthy(&self) -> bool; | |
fn as_option(self) -> Option<Self> { | |
if self.is_truthy() { | |
Some(self) | |
} else { | |
None | |
} | |
} | |
} |
This file contains hidden or 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
trait Truthy: Sized { | |
fn is_truthy(&self) -> bool; | |
fn as_option(self) -> Option<Self> { | |
if self.is_truthy() { | |
Some(self) | |
} else { | |
None | |
} | |
} | |
fn or(self, default: Self) -> Self { |
This file contains hidden or 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 solve(input: &str) -> impl Display { | |
let init: Vec<Cell<usize>> = input | |
.trim() | |
.split(',') | |
.map(|value| value.parse::<usize>().unwrap().into()) | |
.collect(); | |
let mut memory = Vec::new(); |
This file contains hidden or 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
#[derive(Debug, Copy, Clone, PartialEq, Eq)] | |
enum Sign { | |
Positive, | |
Negative, | |
} | |
/// Partially parse a signed integer. Return the sign (if present) and | |
/// the unsigned integer part | |
fn parse_signed<E>(input: &str) -> IResult<&str, (Option<Sign>, u64), E> { | |
pair( |
This file contains hidden or 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::convert::TryFrom; | |
use nom::branch::alt; | |
use nom::bytes::streaming::{is_not, take}; | |
use nom::character::streaming::char; | |
use nom::combinator::{map, map_res, value, verify}; | |
use nom::error::ParseError; | |
use nom::multi::fold_many0; | |
use nom::sequence::{delimited, preceded}; | |
use nom::IResult; |
This file contains hidden or 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
I am the Miaou user with id 5589 and name "Lucretiel" on https://miaou.dystroy.org |
This file contains hidden or 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::io::{self, BufReader, BufWriter, Read}; | |
use std::net; | |
#[derive(Debug, Copy, Clone)] | |
struct SlamParams<'a> { | |
prefix_length: usize, | |
payload: &'a [u8], | |
} | |
fn deliver_payload(mut dest: impl io::Write, params: SlamParams) -> io::Result<()> { |
This file contains hidden or 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::{ | |
hash::Hasher, | |
io, | |
pin::Pin, | |
task::{Context, Poll}, | |
}; | |
use futures::AsyncRead; | |
use pin_project::pin_project; |