Skip to content

Instantly share code, notes, and snippets.

View songzhi's full-sized avatar
😕
Too Lame In Coding

李冬冬 songzhi

😕
Too Lame In Coding
  • Shanghai China
  • 18:21 (UTC +08:00)
View GitHub Profile
@songzhi
songzhi / main.rs
Last active May 16, 2022 08:40
sensor reader
use axum::{
extract::ws::{Message, WebSocket, WebSocketUpgrade},
response::IntoResponse,
routing::get,
Router,
};
use once_cell::sync::Lazy;
use std::{future::Future, net::SocketAddr, time::Duration};
use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
///
/// ## Examples
/// ```
/// enum Foo {
/// Path(String),
/// Count(usize),
/// }
/// let foo = Foo::Path(1);
/// let f: Option<String> = try_match!(foo, Foo::Path(x)=> x);
/// ```
@songzhi
songzhi / dcl_counter.rs
Last active August 23, 2021 08:37
Distributed Cache Line Counter
//! Inspired by [this](http://concurrencyfreaks.blogspot.com/2013/08/concurrency-pattern-distributed-cache.html).
use cache_padded::CachePadded;
use std::sync::atomic::{AtomicUsize, Ordering};
pub struct DistributedCacheLineCounter {
counters: Box<[CachePadded<AtomicUsize>]>,
num_counters: usize,
}