Skip to content

Instantly share code, notes, and snippets.

View astanin's full-sized avatar

Sergey Astanin astanin

View GitHub Profile
@astanin
astanin / matchcolors.py
Created July 18, 2011 00:09
Match colors of the second image to the colors of the first image.
"""Usage: python matchcolors.py good.jpg bad.jpg save-corrected-as.jpg"""
from scipy.misc import imread, imsave
from scipy import mean, interp, ravel, array
from itertools import izip
import sys
def mkcurve(chan1,chan2):
"Calculate channel curve by averaging target values."
fst = lambda p: p[0]
@astanin
astanin / sigmoid-bench.c
Last active July 6, 2023 16:54
Benchmark various sigmoid functions
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>
#define M_PI_2 1.57079632679489661923 /* pi/2 */
#define M_PI_2_INV (1.0/M_PI_2)
#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
#define ERF_COEF (1.0/M_2_SQRTPI)
@astanin
astanin / .XCompose
Created October 29, 2010 09:29
My Compose key configuration
include "/usr/share/X11/locale/en_US.UTF-8/Compose"
# Punctuation
# знаки препинания, необходимые в русском, которых нет в en_US.UTF-8/Compose
<Multi_key> <period> <minus> : "…" U2026 # HORIZONTAL ELLIPSIS, многоточие
<Multi_key> <period> <space> : "…" U2026 # HORIZONTAL ELLIPSIS, многоточие
<Multi_key> <?> <!> : "⁈" U2048 # QUESTION EXCLAMATION, ?!
<Multi_key> <period> <colon> : "…" # ELLIPSIS
# №: набирается в русской раскладке без ухищрений,
@astanin
astanin / Direct_Links_in_Google_Search.user.js
Created September 25, 2012 14:52
Remove indirections from Google search results on all TLDs (GreaseMonkey script)
@astanin
astanin / compare.py
Created October 14, 2010 15:20
Compare two aligned images of the same size
#!/usr/bin/env python
"""Compare two aligned images of the same size.
Usage: python compare.py first-image second-image
"""
import sys
from scipy.misc import imread
from scipy.linalg import norm
"""Counting objects without bias
http://blogs.mathworks.com/steve/2012/12/18/counting-objects-without-bias/
"""
from scipy.misc import imread, imshow
from scipy.ndimage import label
from scipy import asarray, ones, vstack, hstack
from sys import stdout
@astanin
astanin / rmtweets.py
Created November 13, 2012 16:31
Delete tweets older than X days.
#!/usr/bin/env python2
"""Delete tweets older than X days.
Usage:
rmtweets.py [at_least_days_old (default=365)]
"""
# Twitter gives access to only the last 3200 tweets, but if you delete
# more recent tweets, then after some time (a week? a month?) the
@astanin
astanin / opencv_show_webcam_detect_face.py
Created July 12, 2012 12:36
OpenCV example. Show webcam image and detect face.
#!/usr/bin/env python2
"""
OpenCV example. Show webcam image and detect face.
"""
import cv2
TRAINSET = "/usr/share/OpenCV/lbpcascades/lbpcascade_frontalface.xml"
DOWNSCALE = 4
@astanin
astanin / match-colours.py
Created January 31, 2012 16:31
Colour-match two sets of images pairwise, adjust colour bqlance in the first set of images.
#!/usr/bin/env python2
# requires PIL (python-imaging)
import Image
import ImageStat
from sys import argv, exit
from os.path import basename, splitext
@astanin
astanin / shared_getters.cpp
Last active May 28, 2016 18:30
How to share implementation of methods between multiple derived classes in C++ without putting it into the base class. Using the curiously recurring template pattern.
#include <iostream>
/* How to share implementation of methods between multiple derived classes
without putting it into the base class. Using the curiously recurring template
pattern.
Let's assume, that most, but not all of the derived classes are implemented in
a similar way, and have .x and .y members.
It makes sense to write getters and setters only once and share this code