Skip to content

Instantly share code, notes, and snippets.

View 46bit's full-sized avatar
🏳️‍🌈

Miki Mokrysz 46bit

🏳️‍🌈
View GitHub Profile
fn round(mut game: Game<Box<Rng>>,
players: MsgRoom<String>,
spectator_tx: mpsc::Sender<Msg>,
timeout: Milliseconds,
timer: &tokio_timer::Timer)
-> Box<Future<Item = (Game<Box<Rng>>,
MsgRoom<String>,
mpsc::Sender<Msg>,
Milliseconds,
@46bit
46bit / quickcheck-receive.rs
Created March 24, 2017 03:46
In practice it doesn't seem that quickcheck is doing much work here. It's basically just generating random lists, and that's easily done.
use std::time::Duration;
use futures::{Future, Sink, Stream, Poll, Async};
use super::*;
pub struct Receive<I, C>
where I: Clone + Send + Debug + 'static,
C: Sink + Stream + 'static,
C::SinkError: Clone,
C::Error: Clone
{
@46bit
46bit / deadlines.rb
Last active March 23, 2017 03:46
Reminder in each shell of impending project deadline.
# Install these Ruby Gems (packages):
# `gem install colorize humanize`
# Call in your shell profile (e.g., ~/.zshrc):
# `ruby deadlines.rb`
require 'colorize'
require 'humanize'
require 'date'
needed = [[18000, "words"], [55, "pages"]]
fn main() {
let mut xs = vec![Some(5), None, Some(3)];
// Sadly, this never prints.
for x in xs {
let n = x.unwrap_or(continue);
println!("{}", n);
}
}
@46bit
46bit / a.rs
Last active March 18, 2017 21:34
if let Some(&mut rx) = self.rx.as_mut() {
if let Some(item) = match rx.poll() {
Ok(Async::NotReady) => None,
Ok(Async::Ready(item)) => Some(Ok(item)),
Err(e) => Some(Err(CappedError::StreamError(e)))
} {
// Even if the cap is exceeded, buffer this final item.
self.buffer.push_back(item);
// If the updated queue exceeds the buffer size, drop the Stream.
if self.buffer.len() > self.buffer_size {
@46bit
46bit / gadts.rs
Last active March 1, 2017 16:31 — forked from Sgeo/gadts.rs
Gadts in Rust (I tried to see if I could hack in trait-based generics for each variant. Nope. :-()
use std::marker::PhantomData;
use std::ptr;
use std::mem;
use std::ops::Add;
/// This type is only every inhabited when S is nominally equivalent to T
#[derive(Debug)]
pub struct Is<S, T>(PhantomData<(*const S, *const T)>);
// Construct a proof of the fact that a type is nominally equivalent
#![feature(box_syntax, box_patterns)]
#![allow(dead_code)]
use std::ops::{Deref, DerefMut};
use std::collections::VecDeque;
use std::fmt::{Debug, Formatter, Error};
pub struct BoxTree<T>(Box<T>) where T: Tree;
impl<T> BoxTree<T>
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
#[serde(tag = "kind", content = "data", namecasing = "snake_case")]
pub enum Msg {
#[serde(namecasing = "SCREAMING_SNAKE_CASE")]
Version { sirpent: String, protocol: String },
Register {
desired_name: String,
kind: ClientKind,
},
Welcome {
@46bit
46bit / sirpent-protocol-0.4.md
Last active February 20, 2017 09:00
The latest sirpent protocol is pretty much this.
# ======== SERVER COMMS MODEL ========= #
#     ↑↓      PLAYER         SPECTATOR  #
# 01  T       version        version    #
# 02   R      register       register   #
# 03  T       welcome        welcome    #
# -------------  [...]  --------------- #
# 04  T       game           game       #
# 05  T       round          round      #
# 06   R      move           move       #
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
#[serde(tag = "tag")]
pub enum A {
A1 { field: B },
A2,