Skip to content

Instantly share code, notes, and snippets.

View turbohz's full-sized avatar
👑
Keep calm, and git rebase

Gerard Ruiz turbohz

👑
Keep calm, and git rebase
View GitHub Profile
@turbohz
turbohz / how-to-write-hygienic-macros.md
Created June 16, 2024 08:39 — forked from Kestrer/how-to-write-hygienic-macros.md
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

@turbohz
turbohz / netdiag
Last active May 16, 2018 12:43
Network diagnostics scripts
#!/bin/bash
ERROR_NO_NETWORK_CONTROLLER=1
ERROR_NO_NETWORK_INTERFACE=2
# check for network controller
dev_installed() { lspci -v | grep -q "Network controller\|Ethernet controller"; }
if ! dev_installed; then echo "No network controller detected."; exit $ERROR_NO_NETWORK_CONTROLLER; fi
@turbohz
turbohz / .prompt
Last active August 23, 2016 13:40
#! /bin/bash
. ~/.git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWUPSTREAM='auto,verbose'
GIT_PS1_STATESEPARATOR='/'
GIT_PS1_SHOWCOLORHINTS=1
_PS1=$(printf "\n%*s\r/%s" "$((105+$(tput cols)))" '$(_PS="$?";_PSC=$([[ $_PS -ge 1 ]] && echo "\\x1b[1;31m" || echo "\\x1b[0;32m" );printf "${_PSC}%3s\x1b[0m" $_PS)\\\t\' '$(printf "\x1b[30;1m%s/\x1b[0m" $_PWD)')
PROMPT_COMMAND='export _PWD=$(echo "$PWD" | sed -r "s#^$HOME#~#"); __git_ps1 "$_PS1" "\n\[\e[1;32m\]>\[\e[0m\] \[\e[30m\]" "%s";'