Skip to content

Instantly share code, notes, and snippets.

View berkus's full-sized avatar
🪢
~consume.enhance.replicate~

Berkus Decker berkus

🪢
~consume.enhance.replicate~
View GitHub Profile
@berkus
berkus / playground.rs
Created May 5, 2019 09:47 — forked from rust-play/playground.rs
Code shared from the Rust Playground
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 April 16, 2019 16:34 — forked from rust-play/playground.rs
Transmute UB and `as` UB
#![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 November 18, 2022 14:09
Rust macro to impl Eq, PartialEq and Ord
// 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 April 4, 2019 13:21 — forked from alfredkrohmer/xbox-one-wireless-protocol.md
XBox One Wireless Controller Protocol

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
@berkus
berkus / wasmRustNodeExample.md
Created April 4, 2019 06:48 — forked from ilyakmet/wasmRustNodeExample.md
WASM Rust to Node Example

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 March 29, 2019 16:12 — forked from rust-play/playground.rs
Returning Box<dyn Self> via helper trait
trait Trait: AsTrait {
fn get_answer(&self) -> i32;
}
struct S;
impl Trait for S {
fn get_answer(&self) -> i32 { 42 }
}
@berkus
berkus / FindFilesystem.cmake
Created February 18, 2019 10:11
Use std::filesystem or std::experimental::filesystem
# This is from https://github.com/vector-of-bool/pitchfork/blob/develop/cmake/FindFilesystem.cmake
include(CMakePushCheckState)
include(CheckIncludeFileCXX)
include(CheckCXXSourceCompiles)
cmake_push_check_state(RESET)
set(CMAKE_CXX_STANDARD 17)
set(have_fs FALSE)
@berkus
berkus / README.md
Last active February 1, 2019 11:12
Consuming the Twilio Programmable Chat SDK with debug symbols

For purposes of using fabric.io crashlytics or some other debugging needs, you might need to use version of Chat SDK with debug symbols.

Switching to it is easy:

Where you previously had a line implementation 'com.twilio:chat-android:4.0.2' similar to here you should just replace chat-android with chat-android-with-symbols, the full line would look like:

implementation 'com.twilio:chat-android-with-symbols:4.0.2'
@berkus
berkus / playground.rs
Created January 14, 2019 08:02 — forked from rust-play/playground.rs
Code shared from the Rust Playground
#![feature(result_map_or_else)]
extern crate serde; // 1.0.84
extern crate serde_derive; // 1.0.84
extern crate serde_json; // 1.0.34
use serde::Serialize;
#[derive(Debug, Serialize)]
#[serde(tag = "status", content = "result")]