Skip to content

Instantly share code, notes, and snippets.

View astanin's full-sized avatar

Sergey Astanin astanin

View GitHub Profile
@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 / octavelp.nw
Created October 25, 2010 10:17
An example of literate programming (LP) with Octave and Noweb
\section{Programming in Octave}
Just like any other programming language, Octave has its loop and conditional
constructs. The following example demonstrates how to generate the first 10
values of Fibonacci's sequence using a for loop:
<<Fibonacci sequence>>=
fib = [ 0, 1 ];
for i = 3:10
fib = [ fib, fib( i-2 ) + fib( i-1 ) ];
@astanin
astanin / parr.hs
Created November 16, 2010 14:44
Parallel strategy applied to Array
import qualified Data.Array as A
import Control.Parallel.Strategies
ack 0 n = n+1
ack m 0 = ack (m-1) 1
ack m n = ack (m-1) (ack m (n-1))
main = do
let arr = A.listArray (0,999) [1..] :: A.Array Int Int
let res = (fmap (ack 2) arr) `using` parTraversable rdeepseq
%% This program is free software; you can redistribute it and/or
%% modify it under the terms of the GNU General Public License
%% as published by the Free Software Foundation; either version 2
%% of the License, or (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
@astanin
astanin / matchcolors.py
Created July 18, 2011 00:09
Match colors of the second image to the colors of the first image.
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]
snd = lambda p: p[1]
sums = {}
@astanin
astanin / passphrase.lhs
Created September 12, 2011 09:39
A password generator inspired by XKCD #936
#!/usr/bin/env runhaskell
A password generator inspired by XKCD #936: http://xkcd.com/936/
Passwords which are easy for humans to remeber and hard for computers to guess.
> import Control.Monad (liftM, when)
> import Data.List (intercalate, isPrefixOf)
> import System.Random (getStdGen, randomRs)
> import System.Environment (getArgs)
@astanin
astanin / SensorSize.hs
Created September 21, 2011 15:24
diagram of relative sensor sizes
{-# LANGUAGE NoMonomorphismRestriction #-}
import Diagrams.Prelude
import Diagrams.Backend.Cairo.CmdLine
import Diagrams.TwoD.Util (width, height)
pentax_q = (6.16, 4.62) -- as 1/2.3"
oly_xz1 = (7.89, 5.81) -- http://j.mp/qfuFxT
nikon_cx = (13.2, 8.8)
four_thirds = (20.7, 13.8)
@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