Skip to content

Instantly share code, notes, and snippets.

View edef1c's full-sized avatar

edef edef1c

  • Earth
View GitHub Profile
@edef1c
edef1c / playground.rs
Created February 17, 2019 16:08
for .. { .. } else { .. } macro for Rust
macro_rules! for_expr {
( $lhs:pat in $iter:ident $body:block else $else:block ) => {
for_expr!($lhs in ($iter) $body else $else)
};
( $lhs:pat in ($iter:expr) $body:block else $else:block ) => {{
let mut iter = ::core::iter::IntoIterator::into_iter($iter);
if let Some(mut item) = iter.next() {
loop {
let $lhs = item;
let result = $body;
@edef1c
edef1c / default.nix
Last active July 12, 2023 10:09
NixOS module for qemu-user binfmt_misc
{ pkgs, ... }:
let inherit (pkgs) stdenv qemu getopt; in
{
systemd.additionalUpstreamSystemUnits = [
"proc-sys-fs-binfmt_misc.automount"
"proc-sys-fs-binfmt_misc.mount"
];
environment.etc."binfmt.d/qemu-user.conf".source = stdenv.mkDerivation {
name = "qemu-binfmt";
inherit (qemu) src;
define-command nix-jump %{
execute-keys <esc><a-i><a-w>
edit %sh{
if [[ "$kak_selection" =~ ^\<(.*)\>$ ]]; then
path="$(nix-instantiate --find-file "${BASH_REMATCH[1]}")"
else
cd "$(dirname "$kak_buffile")"
path="$(realpath "$kak_selection")"
fi
if [ -d "$path" ]; then
@edef1c
edef1c / sigevent.c
Last active August 13, 2019 03:42
proof-of-concept of siglongjmp/ppoll-based signal handling in an event loop
#define _GNU_SOURCE
#include <err.h>
#include <errno.h>
#include <poll.h>
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@edef1c
edef1c / nixos-option
Last active August 17, 2019 23:22
NixOS deployment scripts
nixos-rebuild
@edef1c
edef1c / ugdb-overlay.nix
Created October 18, 2019 07:21
ugdb packaged for Nix
self: super:
with self;
with rustPlatform;
{
ugdb = buildRustPackage rec {
pname = "ugdb";
version = "0.1.4";
src = fetchFromGitHub {
owner = "ftilde";
@edef1c
edef1c / env-necessary.pl
Last active October 20, 2019 16:29
perl script to check what environment variables a program actually needs to run
#! /usr/bin/env perl
use POSIX ":sys_wait_h";
my @untested = keys %ENV;
sub choose {
return splice @untested, rand @untested, 1;
}
sub works {
building '/nix/store/s103zvdl4nrsi24vl0xvsjmdcphab79m-unit-nix-daemon.service.drv'...
building '/nix/store/4sni1imp36r5mj8vjgphngx2p14aqm1x-system-units.drv'...
building '/nix/store/zf3ypcls84l6pmf516krf888in81syhp-etc.drv'...
building '/nix/store/xxyk1rn73xss107wapp71nkrmdqc1kcg-nixos-system-platypus-20.03pre-git.drv'...
stopping the following units: nix-daemon.service, nix-daemon.socket
activating the configuration...
setting up /etc...
error: cannot connect to daemon at '/nix/var/nix/daemon-socket/socket': Connection refused
Activation script snippet 'nix' failed (1)
reloading user units for edef...
@edef1c
edef1c / 0001-Linux-consider-ZFS-ARC-to-be-cache.patch
Last active May 20, 2020 14:09
ZFS on Linux ARC support patch for htop (multi's revised version)
From 78ade158ed480a6958fd6d477ee90f2bd2d1f668 Mon Sep 17 00:00:00 2001
From: multiplexd <multi@in-addr.xyz>
Date: Sat, 9 May 2020 20:31:35 +0100
Subject: [PATCH v2] Linux: consider ZFS ARC to be cache
This patch adds an arcSize member to the ProcessList struct, and then
adjusts the usedMem and cachedMem values when the memory usage meter is
initialised in Platform_setMemoryValues(), and not earlier.
---
ProcessList.c | 1 +
@edef1c
edef1c / Makefile
Created August 17, 2021 11:59 — forked from glandium/Makefile
Linux kernel module for Zen workaround for rr
obj-m = zen_workaround.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean