Skip to content

Instantly share code, notes, and snippets.

View romac's full-sized avatar
🔮
λ

Romain Ruetschi romac

🔮
λ
View GitHub Profile
@romac
romac / main.rs
Created February 20, 2024 08:33
Compile-time computation of prefix size on stable Rust
const PREFIX_TYPES: &[&str] = &["Compiling", "Downloading", "Fetching", "Printing", "Doing"];
const fn max_prefix_width() -> usize {
let mut max_width = 0;
let mut i = 0;
loop {
if i == PREFIX_TYPES.len() {
break;
}
@romac
romac / Share.swift
Created January 30, 2024 09:16 — forked from mosen/Share.swift
Convenient swift-like wrapper over NetFS smb mounting
import Foundation
import NetFS
enum ShareMountError: Error {
case InvalidURL
case MountpointInaccessible
case InvalidMountOptions
}
@romac
romac / kitty_reload.zsh
Created March 7, 2023 09:04
Set kitty theme based on system mode
kitty_reload() {
DARK_MODE="$(dark-mode status)"
# check if kitty is active
if [[ -n "$KITTY_PID" ]]; then
# set dark theme
if [[ "$DARK_MODE" == "on" ]]; then
kitty @ set-colors --all --configured "$HOME/.config/kitty/theme-dark.conf"
else
kitty @ set-colors --all --configured "$HOME/.config/kitty/theme-light.conf"
@romac
romac / collate.rs
Created July 13, 2022 10:33 — forked from rust-play/playground.rs
Collate a sequence of ordered elements
use std::ops::{Add, RangeInclusive};
struct Collate<Iter, Item> {
iter: Iter,
current: Option<RangeInclusive<Item>>,
}
impl<Iter, Item> Collate<Iter, Item> {
fn new(iter: Iter) -> Self {
Self {
[829/3950] Compiling C++ object libcommon.fa.p/disas_libvixl_vixl_a64_disasm-a64.cc.o
FAILED: libcommon.fa.p/disas_libvixl_vixl_a64_disasm-a64.cc.o
c++ -Ilibcommon.fa.p -I. -I.. -I../dtc/libfdt -I../capstone/include/capstone -Iqapi -Itrace -Iui -Iui/shader -I/usr/local/Cellar/gnutls/3.6.15/include -I/usr/local/Cellar/nettle/3.7.2/include -I/usr/local/Cellar/libtasn1/4.16.0_1/include -I/usr/local/Cellar/libidn2/2.3.0/include -I/usr/local/Cellar/p11-kit/0.23.22/include/p11-kit-1 -I/usr/local/Cellar/libffi/3.3_3/include -I/usr/local/Cellar/glib/2.68.1/include -I/usr/local/Cellar/glib/2.68.1/include/glib-2.0 -I/usr/local/Cellar/glib/2.68.1/lib/glib-2.0/include -I/usr/local/opt/gettext/include -I/usr/local/Cellar/pcre/8.44/include -I/usr/local/Cellar/glib/2.68.1/include/gio-unix-2.0 -I/usr/local/Cellar/jpeg/9d/include -I/usr/local/Cellar/libusb/1.0.24/include/libusb-1.0 -I/usr/local/Cellar/libslirp/4.4.0_1/include/slirp -I/usr/local/Cellar/libpng/1.6.37/include/libpng16 -I/usr/local/Cellar/pixman/0.40.0/include/pi
@romac
romac / cargo-build.txt
Last active December 15, 2020 22:18
Free monads in Rust
$ cargo build
error: reached the recursion limit while instantiating `<FreeFamily<ToyFamily<char>> as ...osure@src/free.rs:53:88: 53:96]>`
--> src/free.rs:53:75
|
53 | Free::Free(box fa) => Free::Free(Box::new(self.0.fmap(fa, |x| self.bind(x, |a| f(a))))),
| ^^^^^^^^^^^^^^^^^^^^^^
|
note: `<FreeFamily<F> as Monad>::bind` defined here
--> src/free.rs:47:5
|
@romac
romac / README.md
Last active June 19, 2020 10:20
Switch between iTerm profiles based on the active macOS theme
newtype ZIO r a
= ZIO (ReaderT r IO a)
deriving newtype (Functor, Applicative, Monad, MonadIO)
unZIO :: ZIO r a -> ReaderT r IO a
unZIO (ZIO z) = z
runZIO :: ZIO r a -> (r | r1) -> IO a
runZIO (ZIO z) r = runReaderT z r
@romac
romac / demo.rs
Created March 15, 2019 12:34
Rocket + frunk Coproduct for type-safe route results
type TestRes = RouteResult<
Created<JsonValue>,
Coprod!(
BadRequest<JsonValue>,
NotFound<JsonValue>,
InternalServerError<JsonValue>
),
>;
#[post("/test/<a>")]
@romac
romac / GenericZ3.hs
Last active May 24, 2017 19:07
Prototype of GHC.Generics-based declaration of ADTs in Z3
{-# LANGUAGE DeriveGeneric
, DefaultSignatures
, FlexibleInstances
, FlexibleContexts
, KindSignatures
, DataKinds
, TypeOperators
, DeriveAnyClass
, ScopedTypeVariables #-}