Skip to content

Instantly share code, notes, and snippets.

View astanin's full-sized avatar

Sergey Astanin astanin

View GitHub Profile
@astanin
astanin / fmtcsv.py
Created March 27, 2012 11:43
Pretty-print CSV file with fixed width columns.
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Usage: %prog [width [columns]] < table.csv
Pretty-print CSV file with fixed width columns.
Arguments:
@astanin
astanin / hyphenation.js
Created March 20, 2012 15:29
GreaseMonkey script to enable CSS hyphenation everywhere
// ==UserScript==
// @name CSS Hyphenation
// @namespace https://github.com/astanin
// @description Enable CSS hyphenation everywhere.
// If lang attribute is missing, lang=defaultLang is assumed.
// Edit script code and set appropriate defaultLang language code.
// @include http://*
// @include https://*
// ==/UserScript==
@astanin
astanin / PKGBUILD
Created March 2, 2012 22:57
PKGBUILD for ArgyllCMS with ColorHUG patch
# Contributor: Frank Ickstadt (frank dot ickstadt at gmail dot com)
# for argyllcms 1.3.5 color management system
# Note for rebuilders:
# The name of the file to be downloaded is always the same!
# So if you are a bad boy (Santa knows everything!) and build as root, this file
# will be saved in /var/cache/pacman/src . Therefore, rebuilding a later version
# likely will fail due to an MD5 error. If so, delete the files from the cache
# to force a new download.
@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 / gtt-feed.hs
Created December 15, 2011 17:02
GTT | Avvisi. Atom feed generator
-- A script to generate Atom feed from a feed-less webpage
import Network.HTTP
import Text.HTML.TagSoup
import Text.Atom.Feed
import Text.Atom.Feed.Export
import Text.XML.Light
import Data.List (isPrefixOf)
import Data.Time (getCurrentTime)
import Control.Monad (liftM)
@astanin
astanin / uncrop.py
Created November 28, 2011 10:34
Uncrop a sequence of Cropped TIFFs
#!/usr/bin/env python
# Public Domain
"""
Uncrop a sequence of Cropped TIFFs[1] generated by Hugin, nona or
PTmender.
Pad images with transparent background to the minimum common extent
according to XPosition, YPosition tags. Images are save to uncrop/
subdirectory.
@astanin
astanin / splitBy.py
Created October 24, 2011 20:25
Split a sequence into two, lazily, in single pass and preserving order.
"""
This module provides splitBy function which splits a sequence into two
subsequences, in single pass and preserving order.
Some tests:
>>> def odd(x): return x%2 != 0
>>> odds, evens = splitBy(odd, range(10))
>>> odds.next()
1
{- Два солдата подошли к реке, по которой на лодке катаются двое
мальчиков. Как солдатам переправиться на другой берег, если лодка
вмещает только одного солдата либо двух мальчиков, а солдата и
мальчика уже не вмещает? -}
import Data.List (intercalate, (\\), sort, nub, permutations)
data C = Boy | Soldier deriving (Show, Eq, Ord)
data S = S { thisbank :: [C], otherbank :: [C] } deriving (Show)
type Move = [C]
{- Крестьянину нужно перевезти через реку волка, козу и капусту. Но
лодка такова, что в ней может поместиться только крестьянин, а с ним
или один волк, или одна коза, или одна капуста. Но если оставить волка
с козой, то волк съест козу, а если оставить козу с капустой, то коза
съест капусту. Как перевёз свой груз крестьянин, если известно, что
все переправились через реку в целости и сохранности? -}
import Data.List (intercalate)
data C = Wolf | Goat | Cabbage deriving (Show, Eq)
@astanin
astanin / embedall.py
Created September 29, 2011 12:30
Embed links to all Flickr photos of a user, separately for every photoset.
#!/usr/bin/env python
from __future__ import with_statement
from cgi import escape
from os.path import expanduser
from string import Template
from sys import argv, version_info, exit
from xml.etree import ElementTree as ET
# import pickle
import warnings