Skip to content

Instantly share code, notes, and snippets.

@promovicz
promovicz / demo.txt
Last active October 25, 2020 10:24
State of CLI
prom@kitten:~$ cli help sho
configuration interface log route
prom@kitten:~$ cli help sho interface
SHOW INTERFACE
Query the interface database
prom@kitten:~$ cli shell
> sh
@promovicz
promovicz / lexer.dylan
Last active October 25, 2020 10:23
CLI lexer
for(char in string, offset from 0)
select(state)
#"initial" =>
case
char.whitespace? =>
maybe-push-collected();
char = '"' =>
state := #"dquote";
char = '?' =>
if(collected-start)
define cli-command $root (fnord)
help "Fnord, whatever that means...";
named parameter file :: <cli-file>,
must-exist?: #t;
named parameter oneof :: <cli-oneof>,
alternatives: #("bla", "blubb", "boo");
end;
@promovicz
promovicz / demo.txt
Last active October 25, 2020 10:21
New dylan command-interface completion and help
prom@horsey:/extra/Projects/opendylan/libraries/command-interface$ _build/bin/command-interface-demo
>
Commands:
configure - Modify configuration
show - Show information
echo - Command
directory - Show information about directory
examine - Command
error - Fail miserably
quit - Quit the shell
@promovicz
promovicz / popcount.c
Created June 20, 2019 02:14
Counting bits with a compiler builtin
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv) {
unsigned word;
int count;
/* check for argument */
if(argc < 2) { printf("Usage: %s INTEGER\n", argv[0]); abort(); }
/* convert argument */
word = (unsigned)atoi(argv[1]);
/* count number of 1-bits */
@promovicz
promovicz / qubes.GetHostsFile
Last active October 24, 2020 19:32
Qubes RPC service generating a hosts file for a firewall VM
#!/bin/bash
# qubes.GetHostsFile - RPC service for retrieving a hosts file
#
# This will emit a hosts file containing the addresses of all qubes
# directly connected to the qube calling the service.
#
# It can be used in firewall VMs to get name resolution for these VMs.
#
# Note that using this script might create an information leak.
@promovicz
promovicz / qvm-restart
Created October 25, 2020 10:21
Qubes domain restart script
#!/bin/sh
# qvm-restart <domain>
#
# Restart the given Qubes DOMAIN, reattaching
# all its network dependents as needed.
#
set -e
@promovicz
promovicz / bin2brl.c
Created November 7, 2020 21:53
Converting binary data into Unicode Braille
#include <errno.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <unistd.h>
int main(int argc, char **argv) {
int res, i;
char buf[64];
@promovicz
promovicz / README.txt
Last active November 16, 2021 03:07
Enhanced dmenu for use with qubes and i3
Example use:
# qubes control
bindsym $mod+u exec --no-startup-id "qubes-i3-dmenu-shell --start"
bindsym $mod+Shift+u exec --no-startup-id "qubes-i3-dmenu-shell --pause"
bindsym $mod+i exec --no-startup-id "qubes-i3-dmenu-shell --shutdown"
bindsym $mod+Shift+i exec --no-startup-id "qubes-i3-dmenu-shell --unpause"
# qubes launching
bindsym $mod+o exec --no-startup-id "qubes-i3-dmenu-shell --global"
@promovicz
promovicz / allmem.c
Created July 7, 2022 17:06
Automatically map unmapped memory
// This little program uses a SIGSEGV handler to auto-map pages as they are used.
// If you want you can use this to program without a memory allocator.
// gcc -std=c11 -Wall -Wextra -g -o allmem allmem.c /usr/lib/x86_64-linux-gnu/libsigsegv.a
#define _GNU_SOURCE 1
#include <stddef.h>
#include <stdint.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <pthread.h>