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
@homm
homm / Default (OSX).sublime-keymap.json
Last active September 27, 2015 11:17
User key bindings for sublime text and modificated duplicate_line.py in /Packages/Default/duplicate_line.py
[
{ "keys": ["super+g"], "command": "find_under", "context":
[
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
]
},
{ "keys": ["super+c"], "command": "noop", "context":
[
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }
]
<?php
$input = '10 20 100 + - 20 * DUP 10 20 + *';
$t = microtime(1);
for ($i = 0; $i < 100000; $i++) {
$stack = array();
foreach (explode(' ', $input) as $chunk) {
switch ($chunk) {
from __future__ import print_function
import time
input = '10 20 100 + - 20 * DUP 10 20 + *';
t = time.time()
for x in xrange(0, 100000):
stack = []
for chunk in input.split(' '):
<?php
function forth_calc($input) {
$stack = array();
foreach (explode(' ', $input) as $chunk) {
if ($chunk === '+') {
$stack[] = array_pop($stack) + array_pop($stack);
} elseif ($chunk === '-') {
$stack[] = array_pop($stack) - array_pop($stack);
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')
@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()
# -*- coding: utf-8 -*-
from PIL import Image, ImageMath
def paste_composite(original, paste):
"""
Вставляет в первое изображение второе, с учетом альфаканала обоих.
Оба изображения должны быть в формате RGBA.
"""
@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)
@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 / 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'