Skip to content

Instantly share code, notes, and snippets.

View homm's full-sized avatar
💭
Fighting JPEG color banding

Alexander Karpinsky homm

💭
Fighting JPEG color banding
  • Uploadcare
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<canvas id="c"></canvas>
<style type="text/css">
@homm
homm / run.sh
Last active June 18, 2016 10:47
#!/bin/bash -e
BRANCHES=( 3.2.0 new-filters resample-adaptve
v3.2.0.post1 v3.2.0.post3 resample-sse-next simd/resample-adaptive )
echo ">>> CPU INFO"
cat /proc/cpuinfo
virtualenv env
source ./env/bin/activate
@homm
homm / ImageMagickTest.sh
Last active July 5, 2016 11:22
Graphic Benchmarks
#!/bin/bash
SRC=$1
RUNS=5
IM="~/ImageMagick8/bin/convert -bench $RUNS -limit thread 1"
# IM="gm benchmark -iterations $RUNS convert -limit threads 1"
RES="2>&1 | grep '=>/dev/null' | grep -Po '\d+:\K\d+\.\d+' | sort | sed '3!d'"
echo -n "Triangle 16x16 "
eval "$IM -verbose $SRC -filter Triangle -resize 16x16! bmp:/dev/null $RES"
@homm
homm / aiostreamsbench.py
Created September 7, 2015 07:45
aiohttp.StreamReader benchmark
import time
import functools
import asyncio
from aiohttp import StreamReader
def make_async(fn):
@functools.wraps(fn)
def async(*args, **kwargs):
f = asyncio.futures.Future()
@homm
homm / django_orm_iterators.py
Last active September 3, 2020 09:49
Memory-efficient task runner for threaded execution. Requires https://pypi.python.org/pypi/futures or python 3.2
from django.db import connections, DEFAULT_DB_ALIAS
def real_queryset_iterator(qs, pk='pk', chunk_size=5000):
qs = qs.order_by(pk)
if pk.startswith('-'):
pk = pk[1:]
lookup = pk + '__lt'
else:
lookup = pk + '__gt'
@homm
homm / threadhell.py
Created June 16, 2013 16:34
Python thread test
import time
import thread
import urllib2
from yurl import URL
from bs4 import BeautifulSoup
class Spider(object):
def __init__(self, base_url, max_threads=50):
@homm
homm / bench.py
Last active December 15, 2015 08:49
#!/usr/bin/env python
from PIL import Image
from timeit import repeat
def prepare_test_images(dim):
"""Plese, be careful with dim > 32. Result image is have dim ** 4 pixels
(i.e. 1Mpx for 32 dim or 4Gpx for 256 dim).
"""
i1 = bytearray(dim ** 4 * 2)
# -*- coding: utf-8 -*-
from PIL import Image, ImageMath
def paste_composite(original, paste):
"""
Вставляет в первое изображение второе, с учетом альфаканала обоих.
Оба изображения должны быть в формате RGBA.
"""
@homm
homm / bench.py
Last active December 15, 2015 08:08
from PIL import Image
from timeit import repeat
from image import paste_composite
im1 = Image.open('in1.png')
im1.load()
im2 = Image.open('in2.png')
im2.load()
from __future__ import print_function
import re
ws_match = re.compile(r'[ \t\n\r]*').match
number_match = re.compile(
r'(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?[ \t\n\r]*',
(re.VERBOSE | re.MULTILINE | re.DOTALL)).match
nan = float('nan')
inf = float('inf')