Skip to content

Instantly share code, notes, and snippets.

View chr5tphr's full-sized avatar

Christopher chr5tphr

  • RIKEN
  • There's no place like 0x7f000001
View GitHub Profile
@chr5tphr
chr5tphr / exportex.sh
Last active February 4, 2022 17:08
Export latex project with a flat figure hierachy.
#!/usr/bin/env bash
set -u
usage() {
cat <<EOF
Usage: "${BASH_SOURCE[0]##*/}" [options] [extra_file ...]
@chr5tphr
chr5tphr / wofind.sh
Created June 28, 2021 20:35
Find a window in sway with wofi and use use it as a criterion in a swaymsg.
#!/usr/bin/env bash
JQWINS='
[recurse(.nodes[])] |
[
.[] |
select(has("app_id")) |
(.id | tostring) + "\t" + .name + (" [" + if .app_id then .app_id else .shell end + "]")
] |
@chr5tphr
chr5tphr / gitupd
Last active July 29, 2022 09:31
Synchronize uncomitted changes
#!/bin/bash
RMTE="${1:?"No host supplied!"}"
RDIR="${2:?"No path supplied!"}"
REPO="${3:-"refs/heads/sync"}"
git push "${RMTE}:${RDIR}" "+@:${REPO}" && git diff HEAD | ssh "${RMTE}" \
"{ git -C '${RDIR}' reset --hard '${REPO}' && git -C '${RDIR}' apply --index - ; }"
@chr5tphr
chr5tphr / combiget.sh
Last active May 22, 2023 13:56
Get elements from a combination of bash arrays given a flat index
#!/usr/bin/env bash
# combiget: get appropriate elements from a combination of arrays given a flat index
combiget() {
ind="${1:?'No index.'}"
arrs=("${@:2}")
for (( i = 0 ; i < ${#arrs[@]} ; i++)); do
n="$ind"
for (( j = i + 1 ; j < ${#arrs[@]} ; j++ )); do
@chr5tphr
chr5tphr / require-venv.sh
Created July 30, 2020 20:03
Require/ install python virtual environment with flock to support concurrent calls.
#!/usr/bin/env bash
RETVAL=0
VENV="${1:?"No path to virtual environment supplied!"}"
shift
exec 3>"${VENV}.lock"
if flock --exclusive --wait 180 3; then
if ! [ -d "$VENV" ]; then
import h5py
import click
@click.command()
@click.argument('sources', nargs=-1, type=click.Path(exists=True, dir_okay=False))
@click.argument('destination', type=click.Path(dir_okay=False, writable=True))
def main(sources, destination):
outfd = h5py.File(destination, 'a')
#!/usr/bin/env python3
import xml.etree.ElementTree as ET
import logging
import os
import click
import yaml
logger = logging.getLogger(__name__)
@chr5tphr
chr5tphr / lazy_proxy.py
Last active October 11, 2019 13:06
LazyProxy Python
"""LazyProxy and LazyDict for lazily evaluated objects"""
class LazyProxy:
"""Lazily apply a chain of functions on a single object"""
def __init__(self, parent=None):
"""Lazily apply a chain of functions on a single object
Parameters
----------
parent : LazyProxy or None
@chr5tphr
chr5tphr / h5tree.py
Last active October 10, 2019 13:03
hdf5 tree visualizer
import h5py
def h5tree(base, key='/', depth=1):
if isinstance(base, h5py.Group):
return key + '\n' + '\n'.join(' ' * depth + h5tree(obj, key, depth + 1) for key, obj in base.items())
else:
blist = str(base[()]).split('\n', maxsplit=1)
return '{}: {}'.format(key, blist.pop(0) + (' (...)' if blist else ''))
@chr5tphr
chr5tphr / pulse_simple_wave.c
Created October 9, 2019 22:37
pulseaudio c wave
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pulse/simple.h>
#include <pulse/error.h>
#define BUFSIZE 1024
void square(short *data, unsigned int length, unsigned int period, short magnitude) {
unsigned int i;