Skip to content

Instantly share code, notes, and snippets.

@salewski
salewski / fstrim.cron
Last active June 30, 2024 16:17
cron/anacron-suitable fstrim(8) invocation
#!/bin/bash -
# SPDX-FileCopyrightText: <text>
# © 2023, 2024 Alan D. Salewski <[email protected]>
# </text>
#
# SPDX-License-Identifier: GPL-2.0-or-later
# This file has been saved as a GitHub Gist here:
#
# https://gist.github.com/salewski/008f75c4a7c572168630fa0fec995959
@salewski
salewski / wmctrl-list-xterms
Last active February 28, 2023 03:26
wmctrl-list-xterms: canned invocation of wmctrl(1) to list details of windows whose WM_CLASS contains "XTerm"
#!/bin/bash -
# SPDX-FileCopyrightText: <text>
# © 2023 Alan D. Salewski <[email protected]>
# </text>
#
# SPDX-License-Identifier: GPL-2.0-or-later
# wmctrl-list-xterms: Canned wrapper around the wmctrl(1) command that invokes
# it with the arguments to list all windows whose WM_CLASS contains "XTerm"
# (e.g., 'xterm.XTerm').
@salewski
salewski / snippet-fill.el
Created January 15, 2021 17:53
emacs: fill.el tweaks to support format=flowed in fill-paragraph
;;; This Gist by Alan D. Salewski <[email protected]>, based on
;;; the 'fill.el' file from GNU Emacs 26.1 as shipped by Debian in
;;; the 'emacs25-lucid' package, version 1:26.1+1-3.2+deb10u1. The
;;; copyright statement from the original file has been preserved below.
;;;
;;; The intent is that this Gist could serve as the starting point
;;; for a proper patch, once I have more time to put such a thing
;;; together.
;;;
;;; Changes here include:

This document is the result of conversations that came out of this tweet: https://twitter.com/withoutboats/status/814201265575981056

Rust's module system is too confusing

Empirically, very many new users of Rust are confused by Rust's module system. This is unfortunate: Rust's module system is not particularly innovative or powerful; it is intended only to provide fairly standard privacy and namespacing support. Too much of new users' attention is being pulled by this system as it exists today.

This document presents an hypothesis of the cause of the confusion, and an attempt to mitigate that confusion by instituting a practice that is more similar to mainstream languages. We believe this problem is caused by the confluence of a several well-motivated design decisions that have created a very unusual system, and the solution is to require less declarations by leveraging ambient information in a manner more similar to how other languages' module systems work.

Rust requires users to build an explicit

@salewski
salewski / rust-join-thread-with-timeout.rs
Last active November 26, 2020 06:00 — forked from junha1/main.rs
Join thread with a timeout
use std::thread;
use std::sync::mpsc::{Receiver, channel};
use std::time::Duration;
struct MyJoin<T> {
handle: thread::JoinHandle<T>,
signal: Receiver<()>
}
impl<T> MyJoin<T> {
@salewski
salewski / snippet-foo.rs
Created November 18, 2020 21:42
rust-lang source file boilerplate
// SPDX-FileCopyrightText: <text> © 2020 Alan D. Salewski <[email protected]> </text>
//
// SPDX-License-Identifier: GPL-2.0-or-later
// Crate-specific settings. Note that we set these here rather than in the
// 'build.rustflags' section of .cargo/config.toml because we want them to
// apply to compilation of our crate only, not to dependency code that we have
// no control over. Also, specifying them via the RUSTFLAGS environment
// variable or via cargo-rustc(1) is much less reliable because we do not have
// any build-tool wrapping (Makefile, GNU Autotools, etc.).
@salewski
salewski / rustup-rustc-versions
Created November 3, 2020 07:26
Print all rustup 'rustc' versions mapped to the corresponding "toolchain" name
#!/bin/bash -
# SPDX-FileCopyrightText: <text> © 2020 Alan D. Salewski <[email protected]> </text>
# SPDX-License-Identifier: GPL-2.0-or-later
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
@salewski
salewski / mdoc.local (snippet)
Last active October 14, 2020 19:02
groff: mdoc.local overrides for Debian GNU/Linux. Append to /etc/groff/mdoc.local
.\" -*-roff-*-
.\" The mdoc \&.Os macro is required to be specified for valid mdoc
.\" pages, but unless the componet being documented is truly specific
.\" to a single operating system, it is recommended that authors omit
.\" the optional argument. That allows for the substitution at render
.\" time for the system current in use.
.\"
.\" For GNU Groff, the values used come from the file:
.\"
@salewski
salewski / on-new-kbd
Last active September 22, 2020 18:27
invoked by inputplug(1) to respond to device add/remove events
#!/bin/bash -
# SPDX-FileCopyrightText: <text> © 2020 Alan D. Salewski <[email protected]> </text>
#
# SPDX-License-Identifier: GPL-2.0-or-later
# on-new-kbd: Applies a canned X11 keyboard config, when invoked.
#
# Intended to be invoked by the inputplug(1) daemon, in response to
# devices being added/removed, enabled/disabled, etc.
#
@salewski
salewski / ~__bin__crontab
Last active September 21, 2020 06:37
Half-unfuck Debian's 'crontab -e' when $EDITOR is emacsclient
#!/bin/bash -
# SPDX-FileCopyrightText: <text> © 2020 Alan D. Salewski <[email protected]> </text>
#
# SPDX-License-Identifier: GPL-2.0-or-later
# This file has been saved as a GitHub Gist here:
#
# https://gist.github.com/salewski/b33ce69a7d8c74587545d5bb65cfd4a4