Skip to content

Instantly share code, notes, and snippets.

View deeuu's full-sized avatar

Dominic Ward deeuu

View GitHub Profile
@deeuu
deeuu / install-xonsh.sh
Created February 7, 2021 11:37
Bash script to install the xonsh shell
#!/usr/bin/env bash
set -e
VIRTUAL_ENV_PATH=${VIRTUAL_ENV_PATH:-"$HOME/.local/share/virtualenvs"}
function yes_or_no {
while true; do
read -p "$* [y/n]: " yn
case $yn in
[Yy]*) return 0 ;;
@deeuu
deeuu / sc_synth_supriya.py
Last active March 26, 2020 21:54
Basic SC Synth example in Supriya
"""
SynthDef(\pure, {|freq=1000| Out.ar(0, SinOsc.ar(freq)); }).add;
Synth(\pure, [\freq, 440]);
"""
import supriya
import time
path = '/Applications/SuperCollider.app/Contents/Resources/scsynth'
server = supriya.Server.default()
server.boot(scsynth_path=path)
@deeuu
deeuu / make_rclone_mount_service.xsh
Last active June 4, 2019 10:13
Script to create a systemd service for mounting an rclone remote
remote = $ARG1
mount_point = f'/mnt/{remote}'
print(f'Creating mount point for user `{$USER}`, (may require root permissions)')
sudo mkdir -p @(mount_point)
sudo chown $USER @(mount_point)
log = f'/tmp/rclone-mount-{remote}.log'
config = f'''[Unit]
@deeuu
deeuu / tkplotlib.py
Last active May 28, 2019 12:14
matplotlib + tkinter
import time
import random
import tkinter as tk
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
class Window():
def __init__(self, root):
self.root = root
@deeuu
deeuu / jsonconfigparser.py
Last active May 29, 2019 16:50
JSON for quick config file
class JSONConfigParser():
import collections
Option = collections.namedtuple('Option', 'type is_required default')
def __init__(self):
self._expected = {}
def add_option(self, option, type, is_required=False, default=None):
self._expected[option] = self.Option(type, is_required, default)
@deeuu
deeuu / folders-to-gphotos-albums.xsh
Last active March 9, 2019 17:42
Xonsh script wrapper around upload-gphotos to upload all personal image/video folders to google-photo albums
# see https://github.com/3846masa/upload-gphotos
import argparse
import os
parser = argparse.ArgumentParser()
parser.add_argument('--folder',
help='Folder of images. Can contain subdirectories')
parser.add_argument('--username', help='Your Google Photos username')
parser.add_argument('--password', help='Your Google Photos password')
parser.add_argument('--ftypes', nargs='+',
@deeuu
deeuu / auto_gopass.xsh
Created December 4, 2018 16:44
Gopass autocompletion for xonsh
sudo echo $(gopass completion bash) > /etc/bash_completion.d/gopass
@deeuu
deeuu / install_julia.xsh
Last active February 26, 2019 21:49
Install julia
version = "1.1.0"
major, minor, patch = version.split('.')
wget f"https://julialang-s3.julialang.org/bin/linux/x64/{major}.{minor}/julia-{version}-linux-x86_64.tar.gz"
tar -xvf f"julia-{version}-linux-x86_64.tar.gz"
cp -r f"julia-{version}" /opt/
ln -sf f"/opt/julia-{version}/bin/julia" /usr/local/bin/julia
rm -r f"julia-{version}-linux-x86_64.tar.gz" f"julia-{version}"
echo "Done: Type 'julia'"
@deeuu
deeuu / tag_version.xsh
Last active December 9, 2019 14:03
Xonsh script for tagging (and pushing the tag) the version of a python package as recorded in __version__.py
about = {}
with open($(find . -d 2 -name '__version__.py').strip()) as f:
exec(f.read(), about)
tag_version = f"v{about['__version__']}"
git tag @(tag_version)
git push origin @(tag_version)
@deeuu
deeuu / lower_case_all.py
Last active September 4, 2018 09:46
Python function to lower case all sub-directories and files in a directory
def lower_case_all(dirname):
import os
for dirpath, dirs, files in os.walk(dirname, topdown=False):
for filename in files:
os.rename(os.path.join(dirpath, filename),
os.path.join(dirpath, filename.lower()))
for adir in dirs: