Skip to content

Instantly share code, notes, and snippets.

import numpy as np
from sklearn import linear_model
def letvec(w):
return np.array([ w.count(k) for k in 'abcdefghijklmnopqrstuvwxyz' ])
freq = [ 8.167, 1.492, 2.202, 4.253, 12.702, 2.228, 2.015, 6.094, 6.966, 0.153,
@rgov
rgov / backup-docker-vols.md
Created April 8, 2020 18:24
Backing up Docker volumes

This is documented.

I'm confused by how docker-compose decides to name volumes, prefixing a garbled directory path to the volume name. Consequently if you rename the directory, a new volume is created.

So I wanted to export the volume contents as a .tar.

MOUNT=/usr/share/elasticsearch/data; \
for VOLUME in {mariner,data_parsers_mariner,optdata_parsers_mariner}_elasticsearch_data; do \
    sudo docker run --rm -v $VOLUME:$MOUNT -v /data/backup:/backup ubuntu \

tar cvf /backup/$VOLUME.tar $MOUNT; \

Flashing Marlin to a Monoprice Maker Select V2

These notes were written March 2020, and may be out of date. I'm flashing Marlin 2.0.4.4 using a Bus Pirate from macOS Catalina.

Support for the Monoprice Maker Select V2, aka Wanhao Duplicator i3 V2.1, has been merged into Marlin, so you should not need to find any third-party code or mysterious config files posted to Reddit years ago.

Install prerequisites:

brew install avrdude platformio
'''
Helps you submit an HTML form like a browser would.
form = Form(soup.find('form', name='my_form'))
requests.request(
form.get_method('login'),
form.get_action('login', relative_to='http://example.com/'),
data=form.fill('login', {
'username': 'bob',
'password': 'hunter2',
color bg = #CDE6D0;
color red = #EB1C25;
color yellow = #F7F100;
color green = #20B25B;
color dark_blue = #0072BC;
color brown = #945539;
color light_blue = #AADFFC;
color purple = #D73998;
color orange = #F5951F;
@rgov
rgov / scheduler.py
Last active January 20, 2020 18:03
#!/usr/bin/env python3
import collections
import datetime
import heapq
import logging
import threading
class Event \
(collections.namedtuple('Event', 'time interval action args kwargs')):
#!/usr/bin/env python3
'''
This is intended to be a simple example of listening on two sockets simultaneously
using Python's http.server and socketserver modules.
'''
import http.server
import select
import socketserver
import math
import random
import sys
import time
nsymbols = int(sys.argv[1]) if len(sys.argv) == 2 else 26
nbits_per_symbol = math.ceil(math.log(nsymbols, 2))
ntotal_values = 2**nbits_per_symbol
ninvalid_values = ntotal_values - nsymbols
class DebugMeta(type):
def __bool__(self):
global is_debug
return is_debug
class DEBUG(object, metaclass=DebugMeta):
def __init__(self, message):
if not type(self):
return
print(message() if callable(message) else message)