Skip to content

Instantly share code, notes, and snippets.

View maedoc's full-sized avatar

marmaduke woodman maedoc

  • now
  • here
View GitHub Profile
@maedoc
maedoc / cerb.sh
Created November 6, 2017 10:06
cheap-o encrypted remote backup
#!/bin/bash
mkdir -p /tmp/cerb_1
sshfs $host_dir /tmp/cerb_1
mkdir -p /tmp/cerb_2
encfs /tmp/cerb_{1,2}
for d in $@
do
@maedoc
maedoc / guacboot.sh
Created October 19, 2017 16:51
a few functions to make it easier to test out Guacamole with Docker
#!/bin/bash
function setup_db() {
docker run -d --name gcpg postgres
echo "waiting for db to spin up..."
sleep 2
docker exec gcpg psql -U postgres -c 'CREATE DATABASE gcdb;'
docker exec gcpg psql -U postgres -c "CREATE ROLE gcu WITH PASSWORD 'foo';"
docker exec gcpg psql -U postgres -c "ALTER ROLE gcu WITH LOGIN;"
docker run --rm guacamole/guacamole /opt/guacamole/bin/initdb.sh --postgres | \
@maedoc
maedoc / Makefile
Last active October 2, 2017 22:43
Centering for SDEs in Stan?
CMDSTAN ?= ~/Downloads/cmdstan-2.17.0
nsim ?= 1
./%: %.stan prelude.stan
$(CMDSTAN)/bin/stanc --o=$*.hpp $*.stan
here=$(shell pwd); cd $(CMDSTAN); make $$here/$@; cd $$here
sim.csv: sim.data.R ./sim
./sim sample algorithm=fixed_param num_samples=$(nsim) data file=sim.data.R output file=sim.csv
@maedoc
maedoc / fixfmtstr.py
Created August 20, 2017 19:54
(Mostly) fix format strings for Py 3.6 to % substitutions
import re
def lines(fname='awssg.py'):
with open(fname,'r') as fd:
for line in fd.readlines():
if "f'" in line:
yield line
def fmt_str(line):
ex = r'f\'(.*)\''
@maedoc
maedoc / scroll_uuid.py
Last active August 11, 2017 00:54
faster iteration over batches of rows with uuid ids
from .models import Thing
import time
all_ids = []
size = 10000
num_items = Thing.objects.count()
qs = Thing.objects.order_by('id')
last_id = qs.first().id
count = 0
@maedoc
maedoc / awssg.py
Created August 9, 2017 21:33
Swaps out CIDR/IP address for SSH access in AWS security group
import boto
import requests
import json
import os.path
# keep the list of cidr/ip addrs we used in the past
known_fname = os.path.expanduser('~/.awssg')
# aws credentials
creds = {
@maedoc
maedoc / tvb_distilled.py
Created June 23, 2017 07:45
tvb algorithms, distilled
from numpy import *
import numpy as np
from numpy.random import randn, rand
def spmat(A):
n = A.shape[0]
m = A != 0 # non-zero mask
a = A[m] # non-zero elements
r, c = argwhere(m).T # non-zero row & col indices
@maedoc
maedoc / transmogrify.py
Created June 12, 2017 09:26
First shot at Cythonizing a whole Python source tree...
import os
import sys
import subprocess
# gcc $(python3-config --cflags) -fPIC -c $file
# gcc -shared $(python3-config --ldflags) utils.o -o utils.so
def flags():
proc = subprocess.Popen(['python3-config', '--cflags'], stdout=subprocess.PIPE)
cflags = proc.stdout.read().decode('ascii')
@maedoc
maedoc / setup-docker-wheezy.sh
Created May 13, 2017 07:55
Install Docker on Wheezy w/ older kernel
#!/bin/bash
apt-get update
apt-get install -y apt-transport-https ca-certificates curl python-software-properties
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
echo "deb [arch=amd64] https://download.docker.com/linux/debian wheezy stable" >> /etc/apt/sources.list
echo "deb http://ftp.debian.org/debian/ wheezy-backports main" >> /etc/apt/sources.list
apt-get update
@maedoc
maedoc / logp.py
Created April 19, 2017 08:14
Optimizing log probability by hand
print('importing')
import numpy as np
import sympy as sp
import scipy.optimize
import random
print('functions')
def gen_trace(n_time, sig, dt, a):
x = random.gauss(0, 3)