Skip to content

Instantly share code, notes, and snippets.

View matthewjberger's full-sized avatar
🦀
Programming something in Rust, probably

Matthew J. Berger matthewjberger

🦀
Programming something in Rust, probably
View GitHub Profile
@dreamsmasher
dreamsmasher / overload.rs
Created October 2, 2022 00:16
Function Overloading in Rust
#![feature(fn_traits, unboxed_closures)]
macro_rules! orelse {
(($($lhs:tt)+), $rhs:tt) => {$($lhs)+};
((), ($($rhs:tt)*)) => {$($rhs)*}
}
macro_rules! overload {
(
$v:vis fn $fn_name:ident {
@andygeorge
andygeorge / steamdeck_ssh_instructions.md
Last active February 21, 2024 06:54
Steam Deck `ssh` instructions

These are manual instructions on enabling SSH access on your Steam Deck, adding public key authentication, and removing the need for a sudo password for the main user (deck).

This gist assumes the following:

  • you have a Steam Deck
  • you have a home PC with access to a Linux shell that can ssh, ssh-keygen, and ssh-copy-id
  • your Steam Deck and home PC are on the same local network, with standard SSH traffic (tcp/22) allowed over that network from the PC to the Steam Deck

NOTE: @crackelf on reddit mentions that steamOS updates blow away everything other than /home, which may have the following effects:

  • removing the systemd config for sshd.service, which would prevent the service from automatically starting on boot
  • removing the sudoers.d config, which would reenable passwords for sudo
@kalkyl
kalkyl / shared-bus-async.rs
Created April 25, 2022 22:59
Async shared spi
use core::{fmt::Debug, future::Future};
use embassy::blocking_mutex::raw::RawMutex;
use embassy::mutex::Mutex;
use embedded_hal::digital::blocking::OutputPin;
pub use embedded_hal::spi::{
blocking, Error, ErrorKind, ErrorType, Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3,
};
use embedded_hal_async::spi;
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
@ssokolow
ssokolow / escape_non_utf8_paths.rs
Last active April 11, 2024 05:42
Code for storing Rust Path/PathBuf data as valid UTF-8 (eg. JSON) strings
/* POSIX paths in JSON via escaping which
doesn't alter valid UTF-8 paths.
The trick is recognizing that JSON can store binary nulls in strings
but nulls are the only character that can't occur in POSIX paths,
so we can use it as an escape character that won't change how existing
serialized paths get interpreted.
Copyright 2018-2020, Stephan Sokolow
#[derive(Copy, Clone)]
enum LinkedList<'a> {
Nil,
Cons(u8, &'a LinkedList<'a>),
}
struct LinkedListIter<'a> {
list: LinkedList<'a>,
}
@ryo-ARAKI
ryo-ARAKI / starship.toml
Last active April 21, 2024 20:49
Starship configuration file
# ~/.config/starship.toml
[battery]
full_symbol = "🔋"
charging_symbol = "🔌"
discharging_symbol = ""
[[battery.display]]
threshold = 30
style = "bold red"
@yhatt
yhatt / marp.md
Last active February 5, 2024 07:52
Marp Next example
marp

Marp

h:250

Markdown presentation ecosystem
@matthewjberger
matthewjberger / Angle.cs
Last active August 9, 2018 20:01
A C# 2D Vector class that can be bound to from a ViewModel and has rectangular and polar representations. (Uses MVVMLightLibs from nuget)
namespace Vector2Example
{
using System;
using GalaSoft.MvvmLight;
public class Angle : ObservableObject
{
private Angle() { }
public static Angle FromRadians(double radians)
{
@spacejam
spacejam / rr-with-rust.md
Last active March 13, 2024 18:51
using rr with rust

using rust with rr

rr is a great debugging tool. it records a trace of a program's execution, as well as the results of any syscalls it executes, so that you can "rewind" while you debug, and get deterministic forward and reverse instrumented playback. it works with rust, but by default if you try it out, it could be pretty ugly when you inspect variables. if this bothers you, configure gdb to use a rust pretty-printer

rr is probably in your system's package manager.

usage

@huytd
huytd / .travis.yml
Last active November 24, 2017 16:03
Travis CI config for Rust/Diesel project
language: rust
rust:
- nightly
cache: cargo
services:
- postgresql
before_script:
- psql -c 'create database build_db;' -U postgres
- echo "DATABASE_URL=postgres://postgres@localhost/build_db" > .env
- cargo install diesel_cli --no-default-features --features=postgres