Skip to content

Instantly share code, notes, and snippets.

@leophys
leophys / godoc.zsh
Last active August 28, 2023 05:16
Optionally colored and fuzzy findable godoc
### colored and fuzzy go doc
if which bat > /dev/null; then
function _godoc() {
if echo $1|grep -q -E "^([a-zA-Z0-9/]+)$"; then
go doc ${@} | bat -p -l md
elif echo $1|grep -q -E "^[a-zA-Z0-9/]+\.[a-zA-Z0-9.]+$"; then
go doc ${@} | bat -p -l go
elif echo $1|grep -q -E "^([a-zA-Z0-9/._-]+)/.*\.[a-zA-Z0-9.]+$"; then
go doc ${@} | bat -p -l go
else
@leophys
leophys / unsafe_ring.rs
Created April 17, 2022 02:10
unsafe_ring.rs
use std::ptr;
#[derive(Clone)]
pub struct Ring<T: Clone> {
head: *mut Node<T>,
capacity: usize,
}
impl<T: Clone> Ring<T> {
pub fn capacity(&self) -> usize {
@leophys
leophys / ref_ring.c
Created April 11, 2022 22:27
A ring in C
#include <stdio.h>
#include <stdlib.h>
struct ring_int {
struct ring_int *next;
int value;
} ring_int;
struct ring_int *new_ring(int capacity, int placeholder);
@leophys
leophys / periodic.rs
Last active April 9, 2022 15:22
recursion-rs
// Playing with cons from https://doc.rust-lang.org/book/ch15-01-box.html
#[derive(Clone)]
pub enum Chain<T: Clone> {
Link(T, Box<Chain<T>>),
Nil,
}
impl<T: Clone> Chain<T> {
pub fn new(capacity: usize, initializer: T) -> Self {
let start = Self::Nil;
@leophys
leophys / note.sh
Last active March 30, 2022 12:20 — forked from chrisdickinson/note.sh
#!/bin/bash
set -e
if [ "z$DEBUG" != "z" ]; then
set -x
fi
_NOTES_PATH=${NOTES_PATH:-~/notes}
export FZF_DEFAULT_OPTS="-m --ansi --preview-window 'right:70%' --preview 'bat --color=always --style=header,grid --line-range :300 ${_NOTES_PATH}/{}'"
@leophys
leophys / tpm2-ssh-keygen.sh
Created November 10, 2021 15:15
Use your tpm2 module to generate an ssh key (archlinux only)
#!/usr/bin/env bash
#
# DISCLAIMER: I am not sure this script won't nuke the content of your tpm module, so please,
# accept this risk before continuing.
#
# This script condensates the receipt found at https://incenp.org/notes/2020/tpm-based-ssh-key.html
# for an archlinux system. Running it will eventually install the dependencies, initialize the
# tpm2_pkcs11 store and generate a token and a key. From the key, an ssh public key will be generated.
# You can customize the some setting with env variables: KEY_PATH overrides the default path where the
# key is stored (~/.ssh/tpm2.key); with KEY_ALGO you can override the algorithm used to generate the key
@leophys
leophys / zfs_on_raspberry_pi_4.md
Created January 13, 2021 20:41
ZFS on raspberry pi 4

How to install ZFS on raspberry pi 4

Pin dependencies

Place this in /etc/apt/preferences.d/90_zfs:

Package: libnvpair1linux libuutil1linux libzfs2linux libzpool2linux spl-dkms zfs-dkms zfs-test zfsutils-linux zfsutils-linux-dev zfs-zed
Pin: release n=buster-backports
Pin-Priority: 990
@leophys
leophys / How_to_raspberry_debian.md
Created January 10, 2021 20:59
How to Debian on a Raspberry Pi

Flash debian on a microSD card to be used on a raspberry pi

Download

Download from here the appropriate image.

Flash

@leophys
leophys / update_bat.sh
Created November 15, 2020 16:29
Script to update bat from the github release page for debian derivatives.
#!/usr/bin/env bash
if ! which curl > /dev/null; then
echo "You need to install curl"
exit 1
fi
if ! which jq > /dev/null; then
echo "You need to install jq"
exit 1
@leophys
leophys / from_aegis_to_pass.md
Last active October 6, 2020 20:40
Migrate from Aegis App to password store

From Aegis to pass

[Aegis][0] is a nice android app to manage OTP tokens. [pass][1] is the password manager for *nix systems. I know that the whole point of the two factor authentication philosophy is to physically separate the bearers of authentication information, but the lifetime of my physical devices is quite random, so WHATEVER: I concoted this procedure to copy the OTP passwords from aegis to pass.