Skip to content

Instantly share code, notes, and snippets.

View izabera's full-sized avatar

Isabella Bosia izabera

  • DDN
  • Flitwick, UK
View GitHub Profile
@izabera
izabera / vivi.cpp
Last active October 7, 2024 15:57
basic autovivifying variables in c++, similar to perl/gawk/...
#include <string>
#include <unordered_map>
#include <variant>
template <typename keytype = std::string, typename valtype = std::string>
struct autovivi {
using maptype = std::unordered_map<keytype, autovivi>;
std::variant<std::monostate, valtype, maptype> valueormap;
autovivi() = default;

This is from man bash:

A pipeline is a sequence of one or more commands separated by one of the control operators | or |&. The format for a pipeline is:

[ time [ -p ]] [ ! ] command [ [ | | |& ] command2 ... ]

This is the only place in which ! can appear. It never prefixes commands, it prefixes pipelines.

A funky shell thingy that I've never seen before

So you're in posix sh and you want to do the equivalent of this in bash:

foo | tee >(bar) >(baz) >/dev/null

(Suppose that bar and baz don't produce output. Add redirections where needed if that's not the case.)

@izabera
izabera / automata.sed
Last active September 8, 2023 01:03
cellular automata in sed
#!/bin/sed -f
# store rule in hold space
1 { h; d; }
# make borders wrap
s/\(.\)\(.*\)\(.\)/>\3\1\2\3\1|/
# do some mucking around that can probably be done more elegantly by someone who is actually good at sed
x; G; h; s/\n.*//; x
@izabera
izabera / snoopfd
Last active August 25, 2022 12:00
Dump what an arbitrary linux process writes to some fd
#!/bin/sh -e
target=${1?usage: $0 pid [fd]}
fd=${2-1}
fifo=fifo.$$
log=log.$$
mkfifo $fifo
echo writing to $log
tee $log <$fifo >/proc/$target/fd/$fd &
#include <ctype.h>
#include <fcntl.h>
#include <linux/openat2.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char **func_that_returns_strings(int nstrings) {
// first dump all the strings into a contiguous buffer, separated by \0
char buf[100];
size_t size = 0;
for (int i = 0; i < nstrings; i++)
#!/usr/bin/env python
import fuse
import time
import sys
import errno
class fs(fuse.Operations):
def getattr(self, path, fh=None):
if "blockme" in path:
musl-gcc -shared -fPIC sys_errlist.c -o libsys_errlist.so
#!/bin/bash -e
rm -rf build
mkdir build
cd build
echo "int main() {" > f.c
limit=${1-500}
for (( i = 0; i < ${1-500}; i++ )) do