Skip to content

Instantly share code, notes, and snippets.

@twolfson
twolfson / README.rst
Last active April 29, 2024 01:46
Evaluation and comparison of various Python templating libraries

gist-python-templating-evaluation

@twolfson
twolfson / README.md
Created July 29, 2015 21:59
How to resolve alembic branch conflicts

alembic is a great tool for managing migrations. However, sometimes you can get your branches divergent due to separate PRs. To resolve this, run the following commands:

# Find out where your branches fork
alembic branches
# abcdef
# ghijkl

# Determine which of the 2 branches is a commit in the new non-master branch
# Open that alembic revision in your editor
@twolfson
twolfson / README.md
Created February 5, 2015 21:22
Toggling between `alembic` databases

alembic is great but lacks an out of the box way to set up running migrations against a specific database (e.g. development, test, production). The following adjustments to its env.py and alembic.ini allow us to target a specific database:

Example:

alembic -x db=development upgrade head

env.py:

@twolfson
twolfson / domvas.js
Last active March 16, 2024 05:33
Gittip button. Forking from http://plnkr.co/edit/UAjp8S?p=preview
"use strict";
(function() {
var supportsCSSText = getComputedStyle(document.body).cssText !== "";
function copyCSS(elem, origElem, log) {
var computedStyle = getComputedStyle(origElem);
@twolfson
twolfson / Geometry.js
Created September 22, 2017 20:41
Documentation and tests for distance squared to segment (distanceSqToSegment)
Geometry.distanceSqToSegment = (function () {
// Define reusable variables to avoid memory thrashing
var ptV1 = [0.0, 0.0, 0.0];
var v2V1 = [0.0, 0.0, 0.0];
// Define and return our actual function
// DEV: We name our function inline as otherwise it's `<anonymous>` in stack traces
return function distanceSqToSegmentFn (pt, v1, v2) {
// Resolve the vectors between our vertices and our point
// DEV: This overwrites our reusable variable values
@twolfson
twolfson / index.js
Last active March 16, 2024 05:32
Globstar demo
// Load in glob and fs
var glob = require('glob'),
fs = require('fs');
// Create a test directory
try { fs.mkdirSync('src'); } catch (e) {}
// Create a nested directory
try { fs.mkdirSync('src/nested'); } catch (e) {}
@twolfson
twolfson / README.md
Created February 23, 2015 22:45
Python unittest `setUp` inheritance

In some cases for Python unit tests, we want to automatically perform setUp methods in as declared in a base class. However, we still want setUp to work as per normal in the subclass. The following code will proxy the new setUp function to run it's base class' and the new one.

# Define a common test base for starting servers
class MyBaseTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        """On inherited classes, run our `setUp` method"""
        # Inspired via http://stackoverflow.com/questions/1323455/python-unit-test-with-base-and-sub-class/17696807#17696807
        if cls is not MyBaseTestCase and cls.setUp is not MyBaseTestCase.setUp:
@twolfson
twolfson / .gitignore
Last active February 9, 2024 04:17
Extracted timezones/country data from Google Calendar
node_modules/
@twolfson
twolfson / README.md
Last active January 22, 2024 07:33
How Python modules are resolved

Python modules have 2 syntaxes for importing.

import x
from x import y

import x

Absolute imports are used for importing top-level modules and only top level modules. These are ones that are globally installed, either inside of Python core or via a package manager (e.g. pip).

@twolfson
twolfson / README.md
Last active January 22, 2024 07:32
Setting up SOPS

I'm learning about SOPS and setting it up as my preferred mechanism for storing secrets. Here are my notes.

PGP

It’s security mechanism is that we (i.e. client) use a PUBLIC key from the receiver (i.e. server) and encode it with a random key (I’m saying nonce but it could be reused)

This varies from RSA and SSH because the server uses a PUBLIC key to identify the client.

Web of trust

Web of trust operates by still using PGP (i.e. encoding with recipient’s public key) but additionally, we can encrypt/sign the data as our own by signing it with the client’s private key.

This means the recipient will initially decrypt via our (i.e. client’s) public key (verifying the source) and then decrypting via their (i.e. server’s) private key to get the data.