Skip to content

Instantly share code, notes, and snippets.

@ambivalentno
ambivalentno / test_client_fake_server.py
Created November 17, 2017 13:48
pytest-asyncio aiohttp client testing with fake server
import asyncio
import pathlib
import socket
import ssl
import pytest
import aiohttp
from aiohttp import web
from aiohttp.resolver import DefaultResolver
@ambivalentno
ambivalentno / svgimagefield.py
Created February 26, 2016 10:24
A form field to handle validation of image + svg.
import sys
from io import BytesIO
from PIL import Image
import xml.etree.cElementTree as et
from django.core.exceptions import ValidationError
from django.forms import ImageField as DjangoImageField
from django.utils import six
@ambivalentno
ambivalentno / plot_squares_two_layers.py
Created February 22, 2015 08:26
Plot squares with pyplot
import matplotlib.pyplot as plt
bbox = {
'n': 52.4311573,
's': 52.3182742,
'e': 5.0683726,
'w': 4.7288558,
}
gh_boxes = [{'s': 52.294921875, 'e': 5.09765625, 'w': 5.0537109375, 'n': 52.3388671875}, {'s': 52.294921875, 'e': 5.0537109375, 'w': 5.009765625, 'n': 52.3388671875}, {'s': 52.294921875, 'e': 5.009765625, 'w': 4.9658203125, 'n': 52.3388671875}, {'s': 52.294921875, 'e': 4.9658203125, 'w': 4.921875, 'n': 52.3388671875}, {'s': 52.294921875, 'e': 4.921875, 'w': 4.8779296875, 'n': 52.3388671875}, {'s': 52.294921875, 'e': 4.8779296875, 'w': 4.833984375, 'n': 52.3388671875}, {'s': 52.294921875, 'e': 4.833984375, 'w': 4.7900390625, 'n': 52.3388671875}, {'s': 52.294921875, 'e': 4.7900390625, 'w': 4.74609375, 'n': 52.3388671875}, {'s': 52.294921875, 'e': 4.74609375, 'w': 4.7021484375, 'n': 52.3388671875}, {'s': 52.3388671875, 'e': 5.09765625, 'w': 5.0537109375, 'n': 52.3828125}, {'s': 52.3388671875, 'e': 5.0537109375, 'w': 5.009765625, 'n': 52.3828125}, {'s': 52.3388671875, 'e': 5.009765625, 'w
Share = {
vkontakte: function(purl, ptitle, text) {
url = 'http://vkontakte.ru/share.php?';
url += 'url=' + encodeURIComponent(purl);
url += '&title=' + encodeURIComponent(ptitle);
url += '&description=' + encodeURIComponent(text);
Share.popup(url);
},
odnoklassniki: function(purl, text) {
url = 'http://www.odnoklassniki.ru/dk?st.cmd=addShare&st.s=1';
@ambivalentno
ambivalentno / login.html
Last active May 3, 2024 23:10
django-crispy-form with bootstrap for django-allauth login. Note: now (2014-08-05) you have to install master allauth from github to override forms.
{% load crispy_forms_tags %}
{% block content %}
{% crispy form %}
{% endblock %}
@ambivalentno
ambivalentno / post_mortem_test
Created August 2, 2013 19:38
sample to look at post-mortem pdb
def first():
jj = 'qqq'
jj = second()
print jj
def second():
jj = 'www'
1/0
return jj