Skip to content

Instantly share code, notes, and snippets.

@djay
djay / fastdownloader.py
Last active March 30, 2022 12:10
a parallel fast downloader written in python. Works in 2.7 with threads. Writes to a single sparse file and handles blocks that slowdown or that error so doesn't slow down at the end of the download
import requests
import io
import time
import threading
import os
"""
TODO: turn this into a requests [TransportAdapter](https://docs.python-requests.org/en/master/user/advanced/#transport-adapters)
So can do the following
@djay
djay / isolated_doctests.md
Last active April 11, 2022 09:20
How to keep your doctests and isolate them too

How to keep your doctests and isolate them too

Let's say you have a project with a long doctest .txt file thats grown and grown. I like doctests for their readability however they tend to encourge tacking on semi related tests to a big txt file. Debugging now takes longer and one failing test results in masking other errors. This is why smaller isolated tests are good.

However you can quickly improve things.

mytest.txt (original)

@djay
djay / gist:20e8c6aa767172c4d3db
Created March 20, 2015 08:15
List Comprehension Notebook
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
@djay
djay / gist:9477048
Created March 11, 2014 00:05
Pillow custom build that isn't isolated from system libraries
[zlib]
recipe = zc.recipe.cmmi
url = ${urls:zlib}
depends-on = ${:url}
[urls]
libjpeg = http://www.ijg.org/files/jpegsrc.v8.tar.gz
libpng = http://prdownloads.sourceforge.net/libpng/libpng-1.5.12.tar.gz?download
libtiff = http://www.imagemagick.org/download/delegates/tiff-4.0.3.tar.gz
zlib = http://zlib.net/zlib-1.2.8.tar.gz
@djay
djay / printview.py
Created June 22, 2012 15:11
Return a pdf from a BrowserView in Plone with plone.subrequest
from StringIO import StringIO
from DateTime import DateTime
from plone.subrequest import subrequest
from urllib import unquote
from ho.pisa import pisaDocument
from pyPdf import PdfFileWriter, PdfFileReader
from Products.Five import BrowserView