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'
@memeplex
memeplex / h2status
Last active May 23, 2016 13:01
h2status is a trivial (about 50 LOC) bash wrapper to i3status that nevertheless allows to conveniently: (i) write custom modules in bash to add full-fledged json entries to the status bar, (ii) write mouse event handlers in bash with access to the full set of event parameters as bash variables, (iii) arbitrarily transform the final output to cha…
#!/bin/bash
function status { :; }
function on_event { :; }
function transform { cat; }
function entry {
echo -ne '{"name":"'$1'","full_text":"'$2'"'${3:+,$3}'},'