Skip to content

Instantly share code, notes, and snippets.

View pstch's full-sized avatar
🔥
/dev/null

pistache pstch

🔥
/dev/null
View GitHub Profile
@pstch
pstch / compact_message.rs
Created February 17, 2023 16:29
compact serialization for mail-parser
use serde::{Serialize, Deserialize};
use std::borrow::Cow;
use mail_parser::{Message, MessagePart, MessagePartId, PartType, Header, Encoding as MimeEncoding, MimeHeaders};
use mail_parser::decoders::{base64::base64_decode, quoted_printable::quoted_printable_decode};
use encoding_rs::{Encoding as TextEncoding, UTF_8};
// TODO:
// - add criterion benchmark, especially to compare deserialization+conversion
// to Message::parse
@pstch
pstch / utils.nix
Created November 19, 2020 20:49
Filtering circular definitions in nested data structures (Nix)
{ lib }:
with builtins;
with lib;
rec {
# Common predicates
nonEmpty = x: length x > 0;
nonEmptyAttrs = x: isAttrs x && nonEmpty (attrNames x);
nonEmptyList = x: isList x && nonEmpty x;
@pstch
pstch / stream-replace.sh
Last active July 18, 2023 11:35
Pipe a file to a process "in-place"
#!/usr/bin/env bash
# stream-replace.sh -- pipe a file to a process "in-place", using fallocate
#
# Copyright (C) 2020 Hugo Geoffroy "pistache" <pistache@lebib.org>
#
# 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 3 of the License, or
# (at your option) any later version.
@pstch
pstch / plaquage_nuage_de_points_sur_plan.md
Created May 29, 2018 15:35
Détermination d'un algorithme permettant de "plaquer" un nuage de points sur un plan
  • points N := nuage de points cible

  • point G := centre de gravité du nuage de points N

  • plan P := plan pointant vers Z, passant par le point le plus bas du nuage de points N

  • début boucle (détermination du premier point de contact)

    • droite xGA := perpendiculaire dans le plan P à (GA)

    • angle aGA := plus petit angle qui fait entrer d'autres points de N en contact avec le plan

    • appliquer une rotation d'axe xGA et d'angle aGA au plan P

  • B := barycentre des points de N en contact avec P (sauf A)
@pstch
pstch / zfs_gpf
Created September 14, 2017 15:28
[ 8528.864841] general protection fault: 0000 [#1] SMP
[ 8528.869202] Modules linked in: dm_mod fuse btrfs xor raid6_pq ufs qnx4 hfsplus hfs minix ntfs vfat msdos fat jfs xfs libcrc32c ext4 crc16 jbd2 crc32c_generic fscrypto ecb lrw gf128mul glue_helper ablk_helper cryptd aes_x86_64 mbcache amdkfd radeon ttm ipmi_devintf kvm_intel iTCO_wdt iTCO_vendor_support drm_kms_helper kvm drm dcdbas irqbypass i2c_algo_bit lpc_ich mfd_core i5000_edac edac_core pcspkr sg serio_raw evdev joydev i5k_amb rng_core shpchp ipmi_si ipmi_msghandler button acpi_cpufreq ip_tables x_tables autofs4 zfs(PO) zunicode(PO) zavl(PO) icp(PO) zcommon(PO) znvpair(PO) spl(O) sr_mod cdrom sd_mod uas usb_storage hid_generic usbhid hid psmouse uhci_hcd ehci_pci ehci_hcd mptsas scsi_transport_sas usbcore mptscsih mptbase usb_common scsi_mod bnx2
[ 8528.893864] CPU: 2 PID: 330 Comm: z_rd_int_7 Tainted: P O 4.9.0-3-amd64 #1 Debian 4.9.30-2+deb9u2
[ 8528.893864] Hardware name: Dell Inc. PowerEdge 2950/0NH278, BIOS 1.1.0 06/21/2006
[ 852
@pstch
pstch / deepmerge.py
Created August 13, 2017 05:18
Python deepmerge algorithm
#!/usr/bin/env python
"""Deep merge algorithm -- Merges multiple values, combining dictionaries by
theirs keys, tuples by their indices, chaining lists and sets, and
replacing by the last merged value for any other type.
"""
# 0. Imports & metadata
# =============================================================================
@pstch
pstch / zfs_pooldiff.py
Last active December 23, 2016 03:04
ZFS pool comparison
# Copyright (C) 2016 Hugo Geoffroy
#
# 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 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
[139741.315562] VERIFY3(0 == hdr->b_l1hdr.b_bufcnt) failed (0 == 1)
[139741.316428] VERIFY3(0 == hdr->b_l1hdr.b_bufcnt) failed (0 == 1)
[139741.316429] PANIC at arc.c:5347:arc_read_done()
[139741.316430] Showing stack for process 270
[139741.316433] CPU: 0 PID: 270 Comm: z_rd_int_7 Tainted: P O 3.16.0-4-amd64 #1 Debian 3.16.36-1+deb8u1
[139741.316434] Hardware name: Dell Inc. PowerEdge 1950/0UR033, BIOS 2.7.0 10/30/2010
[139741.316438] 0000000000000000 ffffffff81512391 ffffffffa0467b65 ffff88039abd3d30
[139741.316440] ffffffffa019b9ff ffffffffa02744e3 ffff880300000030 ffff88039abd3d40
[139741.316441] ffff88039abd3ce0 2833594649524556 726468203d3d2030 6468316c5f623e2d
[139741.316442] Call Trace:
[ 1400.707052] SPL: Loaded module v0.7.0-rc2_4_gf200b83 (DEBUG mode)
[ 1404.921460] ZFS: Loaded module v0.7.0-rc2 (DEBUG mode), ZFS pool version 5000, ZFS filesystem version 5
[ 1453.651377] SPL: using hostid 0x00000000
[ 1525.732667] VERIFY3(psize > 0) failed (0 > 0)
[ 1525.733499] VERIFY3(psize > 0) failed (0 > 0)
[ 1525.733501] PANIC at arc.c:6226:arc_write_ready()
[ 1525.733502] Showing stack for process 25567
[ 1525.733506] CPU: 3 PID: 25567 Comm: z_wr_iss Tainted: P C O 3.16.0-4-amd64 #1 Debian 3.16.36-1+deb8u1
[ 1525.733507] Hardware name: Dell Inc. PowerEdge 1950/0UR033, BIOS 2.7.0 10/30/2010
[ 1525.733510] 0000000000000000 ffffffff81512391 ffffffffa0930b65 ffff8800c8dd3d48
user@gramsci:/tmp/zfsonlinux-build-debug/zfs$ ./configure --enable-debug --with-linux=/lib/modules/3.16.0-4-amd64/source --with-linux-obj=/lib/modules/3.16.0-4-amd64/build
checking for gawk... gawk
checking metadata... META file
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking whether to enable maintainer-specific portions of Makefiles... no
checking whether make supports nested variables... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes