Skip to content

Instantly share code, notes, and snippets.

View U007D's full-sized avatar

Brad Gibson U007D

View GitHub Profile
@U007D
U007D / yocto-pi4.md
Last active July 31, 2023 12:51
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
@U007D
U007D / default_clippy_lints.rs
Created October 6, 2018 15:41
Strict + Safety-Critical `clippy` default lint specification - current as per `clippy` v0.0.212 (2018-10-03)
#![forbid(overflowing_literals,)]
#![deny(unsafe_code)] // Do not remove! Change to `allow` to explicitly opt-in to using `unsafe` (facilitates auditing)
// vvv Safety-critical application lints (pedantic: use for safety-critical applications only) vvv
#![deny(clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::cast_precision_loss,
clippy::cast_sign_loss, clippy::float_cmp_const, clippy::indexing_slicing, clippy::integer_arithmetic,
clippy::maybe_infinite_iter, clippy::option_unwrap_used, clippy::result_unwrap_used,)]
// ^^^ End of safety-critical lint section ^^^
#![warn(clippy::clone_on_ref_ptr, clippy::decimal_literal_representation, clippy::default_trait_access,
clippy::doc_markdown, clippy::else_if_without_else, clippy::empty_enum, clippy::enum_glob_use,
clippy::expl_impl_clone_on_copy, clippy::fallible_impl_from, clippy::filter_map, clippy::if_not_else,