Skip to content

Instantly share code, notes, and snippets.

View torkleyy's full-sized avatar

Thomas Schaller torkleyy

  • Wolf GmbH
  • Bavaria, Germany
View GitHub Profile
@torkleyy
torkleyy / uart_hp.rs
Created June 3, 2025 08:42
How to read from UART at high speed in Rust with serialport-rs
//! High-performance UART reader that uses a dedicated thread to ensure no data is lost.
use std::{
collections::VecDeque,
io::{ErrorKind, Result},
pin::Pin,
task::{Context, Poll},
thread,
time::Duration,
};
@torkleyy
torkleyy / sha256.rs
Created November 6, 2021 16:01
Get SHA-256 of a Rust type
// Following crates are needed:
// sha2, serde, bincode
use serde::Serialize;
#[derive(Serialize)]
struct MyType {
// some fields
}
#! /usr/bin/env bash
# Script to install NixOS from the Hetzner Cloud NixOS bootable ISO image.
# (tested with Hetzner's `NixOS 20.03 (amd64/minimal)` ISO image).
#
# This script wipes the disk of the server!
#
# Instructions:
#
# 1. Mount the above mentioned ISO image from the Hetzner Cloud GUI

Keybase proof

I hereby claim:

  • I am torkleyy on github.
  • I am torkleyy (https://keybase.io/torkleyy) on keybase.
  • I have a public key ASBJCJpHMosVjzd4eE0JLDW2XmLwl_68OSO6JR9-PvbtZwo

To claim this, I am signing this object:

@torkleyy
torkleyy / mapping.json
Created March 7, 2019 07:07
Mapping from ISO 3166-1 alpha-3 to ISO 639-1 (basic subset)
{
"DEU": "de",
"CHN": "zh",
"GRC": "el",
"EST": "et",
"HRV": "hr",
"LVA": "lv",
"LTU": "lt",
"ROU": "ro",
"ITA": "it",
@torkleyy
torkleyy / macro.rs
Created May 15, 2018 15:26
Macro experiments with Rust
($num:expr;$($field:ident),*;$($rev:ident),*) => {
impl<$($field,)*> Pop for ($($field,)*)
where
$($field: Pop),*
{
fn tag() -> Ty {
unreachable!()
}
fn pop_tags(stack: &mut Stack) -> Result<()> {
@torkleyy
torkleyy / unsafe_magic.rs
Created March 31, 2018 14:18
[USE WITH CAUTION, not reviewed] How the compiler drops trait objects in Rust
use std::ptr::write;
#[derive(Clone, Copy, Debug)]
#[repr(C)]
struct FatPtr {
ptr: *mut (),
extra: *const (),
}
trait Foo {
@torkleyy
torkleyy / todo.md
Last active March 26, 2018 18:14
My TODO list for this week
  • Finish shred setup PR
  • Finish shred MetaTable PR
  • Review zakarumych/gfx-chain#4
  • Publish shred
  • Create shred version bump PR for Specs
  • Publish Specs
  • specs_gsf (postponed until Specs is published)
  • Get gsf ready for the first release
  • Test out Amethyst UI code & write together current issues
  • Eventually help out with hal integration
@torkleyy
torkleyy / trait_object.rs
Last active March 26, 2018 06:16 — forked from rust-play/playground.rs
How to cast a generic `T: O` to a generic trait object `O` in Rust
trait Foo {
fn method(&self);
}
trait Cast<T> {
fn cast(t: &T) -> &Self;
fn cast_mut(t: &mut T) -> &mut Self;
}
@torkleyy
torkleyy / gist:c0b90863f61198e3563a39e860208c6b
Last active March 25, 2018 20:35
Specs System Decorator
use specs::System;
use specs::SystemData;
pub struct InstrumentedSystem<T> {
pub system: T,
}
impl<T> InstrumentedSystem<T> {
pub fn new(system: T) -> Self {
InstrumentedSystem {