Skip to content

Instantly share code, notes, and snippets.

View astanin's full-sized avatar

Sergey Astanin astanin

View GitHub Profile
@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 / .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 / 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 / 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 / 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
{- Крестьянину нужно перевезти через реку волка, козу и капусту. Но
лодка такова, что в ней может поместиться только крестьянин, а с ним
или один волк, или одна коза, или одна капуста. Но если оставить волка
с козой, то волк съест козу, а если оставить козу с капустой, то коза
съест капусту. Как перевёз свой груз крестьянин, если известно, что
все переправились через реку в целости и сохранности? -}
import Data.List (intercalate)
data C = Wolf | Goat | Cabbage deriving (Show, Eq)