Skip to content

Instantly share code, notes, and snippets.

View igor-shevchenko's full-sized avatar
🐗

Igor Shevchenko igor-shevchenko

🐗
View GitHub Profile
@igor-shevchenko
igor-shevchenko / examples.py
Created May 18, 2017 19:44
rutermextract — примеры использования параметров https://github.com/igor-shevchenko/rutermextract
# Примеры на Python 2.7
from rutermextract import TermExtractor
term_extractor = TermExtractor()
text = u'Съешь еще этих мягких французских булок да выпей же чаю'
for term in term_extractor(text):
print term.normalized
Абагур-Лесной
Абай
Абшвай
Абакумовский
Аббинокмой
Абонкур-сюр-Сей
Абрикосовый
Абый
Абанкай
Абомей
@igor-shevchenko
igor-shevchenko / pagerank.py
Created January 9, 2014 20:02
Geography game
# coding: utf-8
from collections import Counter
import networkx as nx
def get_cities():
with open('cities.txt') as f:
for line in f:
yield line.strip().decode('utf8').lower()
@igor-shevchenko
igor-shevchenko / pi.c
Created October 31, 2013 11:29
Distributed Monte Carlo estimation of pi using posix message queue
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <math.h>
#include <mqueue.h>
#include <sys/stat.h>
#include <errno.h>
@igor-shevchenko
igor-shevchenko / reduce.py
Created August 30, 2013 07:30
map and filter defined using reduce
def map_(function, iterable):
return reduce(lambda lst, cur: lst + [function(cur)], iterable, [])
def filter_(function, iterable):
return reduce(lambda lst, cur: ((lst + cur) if type(iterable) is str else (lst + (cur,) if type(iterable) is tuple else lst + [cur])) if (function if function is not None else bool)(cur) else lst, iterable, '' if type(iterable) is str else tuple() if type(iterable) is tuple else [])
import Control.Monad
import Control.Concurrent.MVar
type TreeRef a = MVar (MutableTree a)
data MutableTree a = Node { value :: a, left :: TreeRef a, right :: TreeRef a, parent :: TreeRef a }
| Leaf { value :: a, parent :: TreeRef a}
treeChangeValue :: MutableTree a -> (a -> a) -> MutableTree a
treeChangeValue (Leaf a p) f = Leaf (f a) p
treeChangeValue (Node a l r p) f = Node (f a) l r p
@igor-shevchenko
igor-shevchenko / textrank.py
Created June 20, 2013 08:34
TextRank algorithm for text summarization.
from itertools import combinations
from nltk.tokenize import sent_tokenize, RegexpTokenizer
from nltk.stem.snowball import RussianStemmer
import networkx as nx
def similarity(s1, s2):
if not len(s1) or not len(s2):
return 0.0
return len(s1.intersection(s2))/(1.0 * (len(s1) + len(s2)))
@igor-shevchenko
igor-shevchenko / huffman.hs
Last active December 17, 2015 10:58
Huffman coding algorithm
import Data.List (sort, insert, elem, concat)
data HuffmanTree = Leaf { symbol :: Char, weight :: Int} | Node { left :: HuffmanTree, right :: HuffmanTree, symbols :: [Char], weight :: Int} deriving (Show)
instance Eq HuffmanTree where
tree1 == tree2 = (weight tree1) == (weight tree2)
instance Ord HuffmanTree where
tree1 `compare` tree2 = (weight tree1) `compare` (weight tree2)
import Data.List (deleteFirstsBy, null)
import System.IO.UTF8 (readFile)
anagrams :: [Char] -> [String] -> [String]
anagrams [] _ = [""]
anagrams _ [] = []
anagrams letters dictionary =
let currentWord = head dictionary
remainingLetters = removeWord letters currentWord
newDictionary = filterDictionary remainingLetters dictionary