Skip to content

Instantly share code, notes, and snippets.

View hgzimmerman's full-sized avatar

Henry Zimmerman hgzimmerman

View GitHub Profile
@Kestrer
Kestrer / how-to-write-hygienic-macros.md
Created October 17, 2020 05:35
A guide on how to write hygienic Rust macros

How to Write Hygienic Rust Macros

Macro hygiene is the concept of macros that work in all contexts; they don't affect and aren't affected by anything around them. Ideally all macros would be fully hygienic, but there are lots of pitfalls and traps that make it all too easy to accidentally write unhygienic macros. This guide attempts to provide a comprehensive resource for writing the most hygienic macros.

Understanding the Module System

First, a little aside on the details of Rust's module system, and specifically paths; it is

@rust-play
rust-play / playground.rs
Created January 18, 2019 00:18
Code shared from the Rust Playground
macro_rules! debug_dbg {
($($x: tt)*) => {{
if cfg!(debug_assertions) {
dbg!($($x)*)
} else {
$($x)*
}
}}
}
@lightdiscord
lightdiscord / default.nix
Last active October 13, 2022 04:41
Rust and wasm with nixos
with import <nixpkgs> {
overlays = map (uri: import (fetchTarball uri)) [
https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz
];
};
stdenv.mkDerivation {
name = "rust-wasm";
buildInputs = [
cargo-web
@hryniuk
hryniuk / pre-commit-cargo-fmt
Last active February 7, 2024 09:21
Git `pre-commit` hook that checks Rust code style with `cargo fmt`
#!/bin/bash
diff=$(cargo fmt -- --check)
result=$?
if [[ ${result} -ne 0 ]] ; then
cat <<\EOF
There are some code style issues, run `cargo fmt` first.
EOF
exit 1
anonymous
anonymous / playground.rs
Created March 9, 2018 21:24
Rust code shared from the playground
extern crate rayon;
use rayon::iter::IntoParallelIterator;
use rayon::iter::ParallelIterator;
fn main() {
let val = integral(|x| x * x, -1f64, 1f64);
println!("{}", val);
}
fn integral<F>(fun: F, min: f64, max: f64) -> f64
@graceavery
graceavery / harryPotterAliases
Last active September 20, 2024 22:13
bash aliases for Harry Potter enthusiasts
alias accio=wget
alias avadaKedavra='rm -f'
alias imperio=sudo
alias priorIncantato='echo `history |tail -n2 |head -n1` | sed "s/[0-9]* //"'
alias stupefy='sleep 5'
alias wingardiumLeviosa=mv
alias sonorus='set -v'
alias quietus='set +v'