Skip to content

Instantly share code, notes, and snippets.

View U007D's full-sized avatar

Brad Gibson U007D

View GitHub Profile
@U007D
U007D / mos-rust build instructions
Created October 6, 2024 01:02
Building `mos-rust` from source
Note: `mos-rust` is available via https://hub.docker.com. But if you're not on `amd64` and don't mind potentially stale builds
(the docker image is 8 months old and 19,980 commits behind `llvm-mos` as of the time of this writing).
# Installation
## 1. Build & install `llvm-mos` to `/opt/llvm-mos`
### macOS
```fish
sudo mkdir /opt/llvm-mos
sudo chwown "$(whoami)" /opt/llvm-mos
git clone https://github.com/llvm-mos/llvm-mos
@U007D
U007D / yocto-pi4.md
Last active August 8, 2024 21:34
Build Yocto image for RPi4

Raspberry Pi minimal image

This guide intends to summarize the essencial steps performed to build a Raspberry Pi minmal image using Yocto.

Download software dependencies

To build the image we are going to use the Poky and the layers meta-openembedded , meta-raspberrypi .

The list of all meta-raspberrypi dependencies are contained in the Readme.md the provided MACHINE's are listed on the layer-contentens.md

@U007D
U007D / main.rs
Created March 26, 2022 13:51 — forked from jix/main.rs
Lifetime GAT emulation on stable rust
// This is a technique to emulate lifetime GATs (generic associated types) on stable rust starting
// with rustc 1.33.
//
// I haven't seen this exact technique before, but I would be surprised if no one else came up with
// it. I think this avoids most downsides of other lifetime GAT workarounds I've seen.
//
// In particular, neither implementing nor using traits with emulated lifetime GATs requires adding
// any helper items. Only defining the trait requires a single helper trait (+ a single helper impl
// for the 2nd variant) per GAT. This also makes the technique viable without any boilerplate
// reducing macros.
@U007D
U007D / openocd-unmatched.cfg
Created July 17, 2021 01:38 — forked from a4lg/openocd-unmatched.cfg
HiFive Unmatched + OpenOCD configuration (S7+U7 cores; no flash configured)
adapter speed 10000
adapter driver ftdi
ftdi_device_desc "Dual RS232-HS"
ftdi_vid_pid 0x0403 0x6010
ftdi_layout_init 0x0008 0x001b
ftdi_layout_signal nSRST -oe 0x0020 -data 0x0020
set _CHIPNAME riscv
transport select jtag
@U007D
U007D / dedup.rs
Created September 4, 2020 10:43
imperative vs declarative loop - a case where the traditional for loop is easier to read AND write
fn iterative_save<W: Write>(&self, mut wtr: W) -> Result<&Self> {
for row in self {
for (i, col) in row.iter().enumerate() {
match i {
0 => wtr.write_all(col.as_bytes())?,
_ => {
wtr.write_all(b",")?;
wtr.write_all(col.as_bytes())?
}
}
@U007D
U007D / cg_bowling_game.rs
Last active January 4, 2020 14:14
Code Golf Bowling Game
fn main() {
let game = "X 7/ 9- X F8 ⑧/ F6 X X X8/"
.chars()
.filter(|c| !c.is_whitespace())
.fold(Vec::new(), |mut rolls, roll| {
match roll {
'X' => rolls.push(10_u8),
'/' => rolls.push(10 - rolls.last().expect("invalid game score")),
c if c >= '0' && c <= '9' => rolls.push((u32::from(c) - 0x30) as u8),
c if c >= '⑤' && c <= '⑧' => rolls.push((u32::from(c) - 0x245f) as u8),
@U007D
U007D / AutoFacGettingStarted.rs
Last active April 18, 2019 11:29
Getting Started DI example naive Rust implementation from https://autofac.readthedocs.io/en/latest/getting-started/index.html
#![feature(existential_type)]
use chrono::Local;
use std::io::{self, Write};
type Result<T> = std::result::Result<T, failure::Error>;
trait IOutput {
fn write(&self, content: &String) -> Result<()>;
}
struct ConsoleOutput {}
using System;
using Autofac;
namespace DemoApp
{
// This interface helps decouple the concept of
// "writing output" from the Console class. We
// don't really "care" how the Write operation
// happens, just that we can write.
public interface IOutput
@U007D
U007D / di.rs
Last active April 18, 2019 02:03
Simple Dependency Injection
#![feature(existential_type)]
type Result<T> = std::result::Result<T, failure::Error>;
trait MyTrait {
fn greet(&self) -> String;
}
struct MyType {}
@U007D
U007D / .bashrc
Last active October 8, 2019 13:47
.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac