Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
If I don't see it my Focus might

Berkus Decker berkus

🎯
If I don't see it my Focus might
View GitHub Profile
@berkus
berkus / playground.rs
Created Aug 29, 2019 — forked from rust-play/playground.rs
Code shared from the Rust Playground
View playground.rs
#![feature(unboxed_closures, fn_traits)]
fn main() {
let add = |a: i32, b: i32| a + b;
let sqr = |a: i32| a.pow(2);
let add_two = |a: i32| a + 2;
assert_eq!(chain(add, sqr)(2, 3), 25);
assert_eq!(
chain(
@berkus
berkus / playground.rs
Created Aug 2, 2019 — forked from rust-play/playground.rs
Code shared from the Rust Playground
View playground.rs
use std::collections::hash_map::Entry;
use std::collections::HashMap;
trait EntryExt<'a, K, V>: 'a {
fn or_insert_with2<F: FnOnce(&K) -> V>(self, f: F) -> &'a mut V;
}
impl<'a, K, V> EntryExt<'a, K, V> for Entry<'a, K, V> {
fn or_insert_with2<F: FnOnce(&K) -> V>(self, f: F) -> &'a mut V {
match self {
View Dockerfile
# See https://news.ycombinator.com/item?id=20213092
FROM python:3
ARG VERSION=2.1.1.0
RUN pip install pytz passlib bcrypt radicale==$VERSION
ENV RADICALE_CONFIG /etc/radicale/config
RUN mkdir -p /etc/radicale
COPY config $RADICALE_CONFIG
@berkus
berkus / playground.rs
Created May 5, 2019 — forked from rust-play/playground.rs
Code shared from the Rust Playground
View playground.rs
trait Def<T> {
fn def(&self, foo: T) -> bool;
}
impl<T, Func> Def<T> for Func
where Func: Fn(T) -> bool
{
fn def(&self, foo: T) -> bool {
(self)(foo)
@berkus
berkus / playground.rs
Last active Apr 16, 2019 — forked from rust-play/playground.rs
Transmute UB and `as` UB
View playground.rs
#![allow(mutable_transmutes)]
use std::mem::transmute;
fn main() {
let a: Vec<u64> = Vec::new();
let r = &a;
let r: &mut Vec<u64> = unsafe { transmute(r) };
r.push(1488);
println!("{:?}", a);
@berkus
berkus / macro.rs
Last active Apr 14, 2019
Rust macro to impl Eq, PartialEq and Ord
View macro.rs
// From https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=7febfe900dd6be489692040a93b2f7bd
macro_rules! impl_comparisons {
($ty:ty) => {
impl PartialOrd for $ty {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl PartialEq for $ty {
@berkus
berkus / xbox-one-wireless-protocol.md
Created Apr 4, 2019 — forked from devkid/xbox-one-wireless-protocol.md
XBox One Wireless Controller Protocol
View xbox-one-wireless-protocol.md

Physical layer

The dongle itself is sending out data using 802.11a (5 GHz WiFi) with OFDM and 6 Mbit/s data rate:

Radiotap Header v0, Length 38
    Header revision: 0
    Header pad: 0
    Header length: 38
    Present flags
View wasmRustNodeExample.md

WASM Rust to Node Example

Use only > 8.x.x NodeJS version

Install Rust before using this tutorial: curl https://sh.rustup.rs -sSf | sh

Create dirs:

mkdir wasmRustNodeExample

cd wasmRustNodeExample
@berkus
berkus / as_trait.rs
Last active Mar 29, 2019 — forked from rust-play/playground.rs
Returning Box<dyn Self> via helper trait
View as_trait.rs
trait Trait: AsTrait {
fn get_answer(&self) -> i32;
}
struct S;
impl Trait for S {
fn get_answer(&self) -> i32 { 42 }
}
You can’t perform that action at this time.