This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 - ; }" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import xml.etree.ElementTree as ET | |
import logging | |
import os | |
import click | |
import yaml | |
logger = logging.getLogger(__name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 '')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from socket import socket, AF_UNIX | |
from pdb import Pdb | |
from os import unlink, getuid, getpid, chmod | |
from signal import signal, SIGUSR1 | |
def rtrace(signum, frame): | |
spath = '/tmp/{:d}.pdb.{:d}'.format(getuid(), getpid()) | |
with socket(AF_UNIX) as sock: | |
chmod(sock.fileno(), 0o700) | |
sock.bind(spath) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
usg = [] | |
loop { | |
begin | |
usg = ([IO.popen(["df", "--output=used", "--block-size=1024", "."]).readlines[1].to_i] + usg)[0, 5] | |
if usg.length > 4 | |
STDOUT << "\r" << (->(x){x.sum / x.length}).call(usg[0..-2].zip(usg[1..-1]).collect {|x, y| x - y}) << " KiB/s " | |
end | |
sleep 0.5 | |
rescue Interrupt |