Skip to content

Instantly share code, notes, and snippets.

@dcormier
dcormier / enclose.rs
Last active July 29, 2024 02:38
Enclose a string written by a closure in opening and closing chars, or a specified number of parentheses.
/// Encloses the string written by `enclosed` in the opening an closing
/// characters provided.
fn enclose<F>(s: &mut String, open: char, close: char, enclosed: F)
where
F: FnOnce(&mut String),
{
s.push(open);
enclosed(s);
@dcormier
dcormier / main.rs
Created March 7, 2023 19:59
A macro (with examples) to simplify Rust `once_cell` usage
macro_rules! once {
($exp:expr) => {
once!((), $exp)
};
($type:ty, $exp:expr) => {{
static ONCE: once_cell::sync::OnceCell<$type> = once_cell::sync::OnceCell::new();
ONCE.get_or_init(|| $exp)
}};
}
@dcormier
dcormier / chunk.go
Created December 28, 2022 16:15
A generic golang function to reslice a slice into chunks not greater than a specified length.
package main
import (
"testing"
"github.com/stretchr/testify/require"
)
// Chunks re-slices a slice into chunks not longer than the specified max length.
// For example, a slice with seven elements being sliced into chunks of two will
@dcormier
dcormier / git.md
Last active November 19, 2021 20:55
Get handy stats from a git repo
  • Show the first commit: git log --reverse --max-count=1
  • Non-merge commits to master: git rev-list --no-merges master --count
  • Number of non-merge commits in master per author: git shortlog -s -n --no-merges master
  • Merges to master: git rev-list --merges --first-parent master --count

If you want to see the commits in question, you can replace --count with something like --pretty=oneline.

@dcormier
dcormier / rusting.md
Last active August 23, 2020 20:47
On Rusting

On Rusting

Notes from golang dev learning to use Rust.

Beginning

I started by watching this (protip: 1.25x speed is about normal), and following along in vscode (my usual IDE, lately).

Visual Studio Code

@dcormier
dcormier / vpn.md
Created April 29, 2019 12:23 — forked from joepie91/vpn.md
Don't use VPN services.

Don't use VPN services.

No, seriously, don't. You're probably reading this because you've asked what VPN service to use, and this is the answer.

Note: The content in this post does not apply to using VPN for their intended purpose; that is, as a virtual private (internal) network. It only applies to using it as a glorified proxy, which is what every third-party "VPN provider" does.

(A Russian translation of this article can be found here, contributed by Timur Demin.)

Why not?

@dcormier
dcormier / deepequal.go
Last active February 2, 2020 18:29
Golang reflect.DeepEqual() example; does it do what you mean?
// Runable: https://play.golang.org/p/-bkg2k6ymCR
//
package main
import (
"fmt"
"reflect"
"time"
)
@dcormier
dcormier / msg_test.go
Last active October 25, 2023 02:36
golang: parsing emails with mime, mime/multipart and net/mail packages
pacakge msgtest
import (
"io"
"mime"
"mime/multipart"
"net/mail"
"net/textproto"
"os"
"path/filepath"
@dcormier
dcormier / docker-cleanup-resources-windows.md
Last active November 5, 2021 19:21
docker cleanup guide (for PowerShell on Windows): containers, images, volumes, networks