Skip to content

Instantly share code, notes, and snippets.

View stefanfoulis's full-sized avatar

Stefan Foulis stefanfoulis

View GitHub Profile
stefanfoulis /
Last active May 9, 2019 19:36
Create RS256 / RS512 Tokens and private/public keypairs for testing
import datetime
from typing import Iterable
import os
import uuid
import jwt
import pytz
import time
import calendar
stefanfoulis / gist:030d7fa0d6d488c0c31f16652e20dbf4
Created October 26, 2018 19:04
Upgrade Poetry to version from git
RUN pipsi install --python=python3 poetry
# It is kind of hard to install from a .tar.gz of the repo if there is no
# in there.
RUN mkdir -p /tmp/poetry-master && cd /tmp/poetry-master && wget && tar -xzvf bdd7909ce7cb729975f31bfdbb4c756a1dd914dd.tar.gz && cd poetry-bdd7909ce7cb729975f31bfdbb4c756a1dd914dd && poetry build && /root/.pipsi/venvs/poetry/bin/pip3 install --upgrade dist/poetry-0.12.4-py2.py3-none-any.whl
name = "app"
version = "0.1.0"
description = ""
authors = ["None"]
python = "3.6"
hyper = "^0.7.0"
cryptography = "^2.3"
stefanfoulis /
Created November 7, 2017 10:40
Helpers to compare settings and requirements when migrating from a regular project to a divio cloud project
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import pip
import pip.req
import uuid
# from pprint import pprint as pp; import key_requirements_compare; reload(key_requirements_compare); compared=key_requirements_compare.tst(); print(len(compared['old']))
stefanfoulis /
Last active June 29, 2023 12:02
How to resize Docker for Mac Disk image and set the default size for new images

Set the default size for new Docker for Mac disk images

UPDATE: The instructions here are no longer necessary! Resizing the disk image is now possible right from the UI since Docker for Mac Version 17.12.0-ce-mac49 (21995).

If you are getting the error: No space left on device

Configuring the qcow2 size cap is possible in the current versions:

# my disk is currently 64GiB
test_basic (__main__.AWS4Auth_AmzCanonicalPath_Test) ... ERROR
test_handle_basic_quoting (__main__.AWS4Auth_AmzCanonicalPath_Test) ... ERROR
test_handle_path_normalization (__main__.AWS4Auth_AmzCanonicalPath_Test) ... ERROR
test_handle_percent_encode_non_s3 (__main__.AWS4Auth_AmzCanonicalPath_Test) ... ERROR
test_handle_percent_encode_s3 (__main__.AWS4Auth_AmzCanonicalPath_Test) ... ERROR
test_handle_querystring (__main__.AWS4Auth_AmzCanonicalPath_Test) ... ERROR
test_basic (__main__.AWS4Auth_AmzCanonicalQuerystring_Test) ... ok
test_multiple_params (__main__.AWS4Auth_AmzCanonicalQuerystring_Test) ... ok
test_quoting (__main__.AWS4Auth_AmzCanonicalQuerystring_Test) ... ok
test_space (__main__.AWS4Auth_AmzCanonicalQuerystring_Test) ... ok
stefanfoulis /
Created September 13, 2016 10:06
Snippets for an eventual better django-dbcache app


A django cache backend that treats the db cache as a first class citizen.

The cache backend in django.core.cache.backends.db only works on the default database connection. Using the same connection as for regular model access can cause weird transaction related deadlocks and similar

stefanfoulis /
Last active September 15, 2015 15:54
super naive open files check for datadog
from checks import AgentCheck
class FileDescriptorCheck(AgentCheck):
def check(self, instance):
with open('/proc/sys/fs/file-nr', 'r') as fobj:
fd_open, unknown, fd_max ='\t')
self.gauge('system.fd_open', int(fd_open))
self.gauge('system.fd_max', int(fd_max))
self.gauge('system.fd_open_pct', float(fd_open)/float(fd_max))
stefanfoulis / gist:dda6b4a2ba91a615b9bb
Created May 24, 2015 20:30
accessing the django file object
# f is the File model
f = filer.models.File.objects.get(...)
# f.file is a django file field (for images it's an easy-thumbnails image field)
stefanfoulis /
Created September 16, 2014 09:05
delete docker logs
find /var/lib/docker/containers/ -type f -name "*.log" -delete