Skip to content

Instantly share code, notes, and snippets.

View astanin's full-sized avatar

Sergey Astanin astanin

View GitHub Profile
@astanin
astanin / pageintotwo.sh
Created January 29, 2010 20:24
Convert PDF to DjVu with cutting every page into two
#!/bin/bash
# растеризовать все страницы в двутональные картинки (для цветных убрать -mono)
pdftoppm -r 600 -mono $1 rawpage
# каждую страницу сжать в чёрно-белый DjVu (cjb2, для цветных использовать c44)
for p in `ls -1 rawpage-*.pbm`; do
# вырезать левую половину: -gravity West -crop 50%x100% +repage
# или правую: -gravity East -crop 50%x100% +repage
# обрезать поля: -trim +repage
@astanin
astanin / upsidedown.lhs
Created March 18, 2010 11:20
Upside down
#!/usr/bin/env runhaskell
> import Data.Char (toLower)
Once @malfet wrote: uʍop ǝpısdn ǝʇıɹʍ oʇ pǝsn ǝq uɐɔ sloqɯʎs sɔıʇǝuoɥd.
Indeed, there are upside-down pairs for most of the lower-case letters.
Only 'j' is a problem.
> abc = [ ('a', 'ɐ'), ('b', 'q'), ('c', 'ɔ'), ('d', 'p'), ('e', 'ə')
@astanin
astanin / tikz-anglearc.tex
Created May 26, 2010 16:26
Draw an angle on tikz plots (LaTeX)
% draw an angle arc on tikz plots
%
% #1: A point of ∠ABC
% #2: B point of ∠ABC
% #3: C point of ∠ABC
% #4: arc radius (length units)
% #5: arc style (e.g. fill=red!50!white or draw)
% #6: label
%
% Issues:
@astanin
astanin / twidge-unicode-from-getArgs.diff
Created June 3, 2010 13:50
Patch to twidge to fix Unicode support in getArgs
diff --git a/twidge.cabal b/twidge.cabal
index 6883036..428e628 100644
--- a/twidge.cabal
+++ b/twidge.cabal
@@ -49,7 +49,7 @@ Flag withBitly
Executable twidge
Build-Depends: network, unix, parsec, MissingH>=1.0.0,
mtl, base >= 4 && < 5, HaXml>=1.13.2, HaXml<1.19, hslogger, hoauth,
- ConfigFile, directory, HSH, regex-posix, utf8-string, binary,
+ ConfigFile, directory, HSH, regex-posix, utf8-string >= 0.3.5, binary,
@astanin
astanin / revdeps-by-license.hs
Created June 3, 2010 17:51
Count Hackage reverse dependencies by license type
{- Count reverse dependencies by license type.
Output on 20100603 (license, # of revdeps, # of packages, revdeps per package):
BSD3 33469 1519 22.033574720210666
LGPL 1018 99 10.282828282828282
GPL 603 334 1.8053892215568863
OtherLicense 300 77 3.896103896103896
PublicDomain 214 64 3.34375
BSD4 53 4 13.25
(tool-bar-mode 0)
(scroll-bar-mode 0)
(menu-bar-mode 0)
(defun add-subdirs-to-load-path (dir)
(let ((default-directory (concat dir "/")))
(normal-top-level-add-subdirs-to-load-path)))
;;; My location for external packages.
(add-to-list 'load-path "~/.emacs.d/site-lisp")
@astanin
astanin / yandexfotki.vim
Created July 24, 2010 09:52
Скрипт для Vim: Переформатировать код для вставки альбома Яндекс-фоток (поставить ссылки на оригиналы)
" Change HTML of Yandex fotki album snippet.
" vim: set expandtab ts=4 sw=4 ai si ci:
function! FixYandexFotkiSnippet()
" remove cuts
s#<lj-cut><cut><!--more-->##
s#</cut></lj-cut>##
" remove wrapping links
s#</\?a[^>]*>##g
" remove hardcoded border, replace with CSS class
s#border="0"#class="whitebg"#g
@astanin
astanin / pdfgrep.sh
Created October 7, 2010 16:39
Grep wrapper to search in PDF files
#!/bin/sh
# grep wrapper to look into PDF files
# supports -i, -c, -v options
# depends on pdftotext
# known bugs:
# FIXED 1. does not suppot spaces in the pattern
# 2. does not support grep -r
# WONTFIX 3. does not support grep -f (it is used to keep pattern)
@astanin
astanin / fix_yandex_fotki_snippet.sed
Created October 12, 2010 12:52
Переформатировать код для вставки альбома Яндекс-фоток (поставить ссылки на оригиналы)
#!/bin/sed -f
# remove cuts
s|<lj-cut><cut><!--more-->||
s|</cut></lj-cut>||
# remove wrapping links
s|</\?a[^>]*>||g
# remove hardcoded border, replace with CSS class
s|border="0"|class="whitebg"|g
# separate by blank links
@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