Skip to content

Instantly share code, notes, and snippets.

@Meyermagic
Meyermagic / cobs_codec.rs
Created October 10, 2018 03:58
Tokio Codec implementation of COBS packet framing
use bytes::BytesMut;
use cobs::{decode_vec_with_sentinel, encode_with_sentinel, max_encoding_length};
use tokio::codec::{Decoder, Encoder};
enum CobsCodecError {
MaxEncodeBufferSizeExceeded,
MaxDecodeBufferSizeExceeded,
CobsDecodingError,
IoError(::std::io::Error),
}
@Meyermagic
Meyermagic / diary.sh
Created April 8, 2018 21:13
Simple bash function for journal entries or notes.
function diary() {
root="$HOME/Documents/journal"
date="$(date -u +"%Y/%m/%d")"
dir="$root/$date"
name="$(date -u +"%T")"
if [ ! -z "$1" ]; then
name+=" '$1'"
fi
@Meyermagic
Meyermagic / quine.rs
Created April 8, 2018 04:24
Quine I wrote a while back. 85 characters
fn main(){(|a|print!("{}({:?})}}",a,a))("fn main(){(|a|print!(\"{}({:?})}}\",a,a))")}
data:text/html, <html contentEditable=true style="caret-color: transparent; color: white; background-color: black;"><head><link rel="shortcut icon" href="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=" type="image/gif"><title>Black</title>
"dein Scripts-----------------------------
if &compatible
set nocompatible " Be iMproved
endif
" Required:
set runtimepath^=/home/meyer/.config/nvim/repos/github.com/Shougo/dein.vim,/nix/store/zan6v7jn67dz3m2axnarvx2k1gxv0dah-neovim-0.1.3/share/nvim/runtime
" Required:
call dein#begin(expand('/home/meyer/.config/nvim'))
<html>
<head>
<meta charset="utf-8">
<link href="style.css" rel="stylesheet">
</head>
<body>
<nav class="topbar">
<ol class="path">
<li class="directory">
<span class="slash">/</span>
struct MemoryDB {
db: HashMap<ThreadID, (ThreadBody, Vec<PostBody>)>,
}
impl Database for MemoryDB {
fn get_threads(&self) -> Vec<Thread> {
self.db.iter().map( |(&thread_id, &(body, _))| Thread{id: thread_id, body: body} ).collect()
}
fn get_posts(&self, thread_id: ThreadID) -> Option<Vec<Post>> {
#![feature(macro_rules)]
macro_rules! alternative(
($in_expr:expr, $pat:pat, $out_true_expr:expr, $out_false_expr:expr) => (
match $in_expr {
$pat => $out_true_expr,
_ => $out_false_expr,
}
);
)
//Counts the number of (non-overlapping) elements matching at the start and end of each slice
fn common_affix<E: TotalEq>(old: &[E], new: &[E]) -> (uint, uint) {
let shorter = min(old.len(), new.len());
let mut common_prefix = 0;
for i in range(0, shorter) {
if old.get(i) != new.get(i) {
break;
}
common_prefix += 1;
.PHONY : all
all: thiscrate
.PHONY : thiscrate
thiscrate: libothercrate
rustc -L . -O main.rs
.PHONY : libothercrate
libothercrate: