Skip to content

Instantly share code, notes, and snippets.

View asaaki's full-sized avatar
🦀
Oh crab!

Christoph Grabo asaaki

🦀
Oh crab!
View GitHub Profile
@asaaki
asaaki / skip_null_values.rs
Created November 17, 2025 18:01
rust serde skip_null_values helper
fn skip_null_values<S, K, M>(map: &M, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
K: serde::Serialize,
M: ?Sized,
for<'a> &'a M: IntoIterator<Item = (&'a K, &'a Value)>,
{
use serde::ser::SerializeMap;
let mut ser_map = serializer.serialize_map(None)?;
for (k, v) in map {
use std::io;
use std::io::Write;
use std::fmt::{Debug, Formatter, Error};
use std::thread;
use std::time::Duration;
use std::sync::{Arc, Mutex};
#[derive(Clone)]
struct Output<W>(Arc<Mutex<W>>);
@asaaki
asaaki / fizzbuzze.rs
Created July 26, 2024 22:35
oceanically moisted fizzbuzz
type Predicates = std::collections::BTreeMap<Predicate, String>;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
struct Predicate(fn(u64) -> bool);
fn main() {
let inputs = 0..=100;
let mut predicates = Predicates::new();
predicates.insert(Predicate(|v| v % 3 == 0), "Fizz".to_string());
predicates.insert(Predicate(|v| v % 5 == 0), "Buzz".to_string());
@asaaki
asaaki / changed-files.sh
Created July 22, 2024 16:57
[git] get list of files which changed
# unstaged changes
git diff --name-only --diff-filter=ACMR | sed 's| |\\ |g'
# staged changes
git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g'
@asaaki
asaaki / help.mk
Created May 21, 2024 16:04
Makefile help
hello: ## sends greetings
@echo "Hello!"
help: ## prints the help
@echo "# Makefile Help #"
@grep -E '^[a-zA-Z0-9_-]+:.*##' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":([^:])*?## "}; {split($$1,m,/:/); if (!m[2]) m[2]=$$1; printf "\033[36m%-30s\033[0m %s\n", m[2], $$2}'
@asaaki
asaaki / lint-staged.sh
Created September 8, 2023 10:28
[ruby] rubocop, but only check git staged files
#!/bin/sh
# time execution
time bin/rubocop -L --stderr $(git diff --name-only --cached | grep '\.rb')
# bare minimum
bin/rubocop $(git diff --name-only --cached | grep '\.rb')
# -L = list files (good to see which one got checked since we don't see the nested command's output
# --stderr = may or may not be useful to pipe output there
@asaaki
asaaki / containers-and-clone.rs
Last active July 16, 2023 11:50 — forked from rust-play/playground.rs
[rust] How to avoid leaking trait bounds (to avoid such changes to be breaking changes)
// https://rust-lang.github.io/api-guidelines/future-proofing.html
/*
The following traits should never be used in bounds on data structures:
* Clone
*/
#[derive(Clone, Debug)]
@asaaki
asaaki / delete-branch.yaml
Last active September 17, 2021 09:04
Automatically delete branches of unmerged pull requests
# .github/workflows/delete-branch.yaml
name: Delete unmerged branch
on:
pull_request:
branches: [ main ]
types: [ closed ]
jobs:
worker:
@asaaki
asaaki / Dockerfile
Last active March 15, 2021 20:24
PostgreSQL 11.5 with pglogical 2.2.2 as docker image
FROM postgres:11.5
RUN apt-get update && apt-get install -y curl
RUN curl https://dl.2ndquadrant.com/default/release/get/deb | bash && apt-get update
### IMPORTANT: use 2.2.2 instead of 2.2.1! Otherwise PG 11.5 is very sad!
RUN apt-get install -y -V postgresql-${PG_MAJOR}-pglogical=2.2.2-1.stretch+1
# the following copied from https://github.com/reediculous456/docker-pglogical/blob/master/Dockerfile
@asaaki
asaaki / .gitconfig
Last active October 14, 2022 03:06
Using different emails and GPG keys for work and personal stuff on GitHub
[core]
# ...
[init]
defaultBranch = main
[commit]
gpgsign = true
# you want that to have a default for locations outside of your regular dev folders