Skip to content

Instantly share code, notes, and snippets.

@virtuald
virtuald / sshpass.py
Created December 20, 2014 19:49
Simple python wrapper to give SSH a password for automation purposes (with output capture)
#!/usr/bin/env python3
import os
import sys
_b = sys.version_info[0] < 3 and (lambda x:x) or (lambda x:x.encode('utf-8'))
def ssh_exec_pass(password, args, capture_output=False):
'''
Wrapper around openssh that allows you to send a password to
@virtuald
virtuald / bpmdetect.py
Last active December 13, 2023 17:43
GStreamer BPM Detector frontend
#!/usr/bin/env python
'''
Simple program that uses the 'bpmdetect' GStreamer plugin to detect
the BPM of a song, and outputs that to console.
Requires GStreamer 1.x, PyGObject 1.x, and gst-plugins-bad
Copyright (C) 2015 Dustin Spicuzza
This program is free software; you can redistribute it and/or modify
#
# Playbin bug: Play 2 flac files (presumably of any length), and play
# 2 mp3 files, using gapless playback, and weirdness happens
#
# On GST 1.4.5, track4.mp3 stalls for ~10s or so without playing, but
# there is no audio for track3 or track4. Other tests I've conducted
# track3 does have audio, but there is still a pause.
#
# On GST 1.5.2, there is no volume for track3 or track4.mp3, but no
# stall occurs. Seems like a bug.
@virtuald
virtuald / context_local.py
Last active June 18, 2020 08:10
Implements a threadlocal-like mechanism for Tornado
'''
This is significantly derived from StackContext, Apache 2.0 license
'''
from tornado.stack_context import StackContextInconsistentError, _state
class ContextLocal(object):
'''
Implements a threadlocal-like mechanism that can be used to track data
across tornado asynchronous calls. This is very similar to (and based
@virtuald
virtuald / route+custom.js
Last active October 12, 2018 23:58
Rewrite of riot.js tag router
(function (riot, route) {
'use strict';
//
// Modified version of the riot-router tags
//
// - Intended to be used recursively. You can even use multiple routers in a tag and they'll work
// - Each 'route' event receives the parent container, and any arguments that it would normally get
// - Child tags receive an attribute 'route_path' which contains the current routing
// - Adding a '/@@' to the end of a route allows the route to have subordinate routers
@virtuald
virtuald / anyerr.go
Created September 13, 2018 00:38
Similar to golang.org/x/sync/errgroup
package anyerr
// portions derived from golang context package, BSD license
import (
"github.com/hashicorp/go-multierror"
"sync"
)
// closedchan is a reusable closed channel.
@virtuald
virtuald / Vagrantfile
Created August 11, 2018 22:03
Vagrant NFS4 client+server automated setup
$serverScript = <<-SCRIPT
sudo apt-get update
sudo apt-get -y install nfs-kernel-server
sudo mkdir -p /exports/share
sudo chown -R vagrant:vagrant /exports
echo "/exports 192.168.50.0/24(rw,fsid=0,no_subtree_check,sync,sec=sys)" > /etc/exports
@virtuald
virtuald / data.json
Created May 1, 2018 18:15
Simulated drivetrain characterization data
{
"slow-forward": [
[21.084223, 12.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[21.104242, 12.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[21.124327, 12.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[21.144219, 12.0, 0.001, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[21.164237, 12.0, 0.001, 0.012, 0.012, 0.0, 0.0, 0.0, 0.0],
[21.184224, 12.0, 0.001, 0.012, 0.012, 0.0, 0.0, 0.0, 0.0],
[21.204217, 12.0, 0.002, 0.012, 0.012, 0.0, 0.0, 0.0, 0.0],
[21.224186, 12.0, 0.002, 0.024, 0.024, 0.0, 0.0, 0.0, 0.0],
@virtuald
virtuald / patch_pathlib2.py
Created December 8, 2017 19:27
monkeypatch 'globmatch' function onto pathlib2
#
# monkeypatch to add 'globmatch' function to PurePath, which implements
# the same style of matching that glob supports (which is different
# from what match supports)
#
# Same license as pathlib2 (MIT license)
#
from __future__ import print_function
from pathlib2 import PurePath,PurePosixPath
@virtuald
virtuald / test.cfg
Last active September 6, 2017 21:44
ns2html netscreen config file (GPL, from http://ns2html.sourceforge.net/download.html)
set clock timezone 0
set vrouter trust-vr sharable
set vrouter "untrust-vr"
exit
set vrouter "trust-vr"
unset auto-route-export
exit
set service "TCP_123" protocol tcp src-port 0-65535 dst-port 123-123
set auth-server "Local" id 0
set auth-server "Local" server-name "Local"