Skip to content

Instantly share code, notes, and snippets.

View lokimckay's full-sized avatar
🐲
Dauður maður safnar engum vörum

Loki McKay lokimckay

🐲
Dauður maður safnar engum vörum
View GitHub Profile
@lokimckay
lokimckay / workspace-dir.rs
Created October 12, 2025 07:15
Get the workspace root directory of a rust project. Useful for `build.rs` scripts
/// Traverse up to the workspace root. Panics if no `[workspace]` is found in any Cargo.toml files.
fn workspace_dir() -> PathBuf {
let crate_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"));
let mut dir = Some(crate_dir.as_path());
while let Some(current) = dir {
let toml_path = current.join("Cargo.toml");
if toml_path.exists() {
if let Ok(contents) = fs::read_to_string(&toml_path) {
if contents.contains("[workspace]") {
return current.to_path_buf();
@lokimckay
lokimckay / git-clean-branches.sh
Last active August 27, 2020 05:44
Delete all local git branches except develop and master
# Delete all local git branches except develop and master
git branch | grep -v "master\|develop" | xargs git branch -D
# Save above command as "git clean-branches" alias
git config --global alias.clean-branches "!git branch | grep -v 'master\|develop' | xargs git branch -D"
# References
# https://coderwall.com/p/x3jmig/remove-all-your-local-git-branches-but-keep-master
# https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases
@lokimckay
lokimckay / scrollfix.css
Last active October 30, 2018 05:19
Consistent horizontal element position between pages with and without vertical scrollbar
html, body {
margin-right: calc((100vw - 100%) * -1);
}