Skip to content

Instantly share code, notes, and snippets.

Igor Shevchenko igor-shevchenko

Block or report user

Report or block igor-shevchenko

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@igor-shevchenko
igor-shevchenko / examples.py
Created May 18, 2017
rutermextract — примеры использования параметров https://github.com/igor-shevchenko/rutermextract
View examples.py
# Примеры на Python 2.7
from rutermextract import TermExtractor
term_extractor = TermExtractor()
text = u'Съешь еще этих мягких французских булок да выпей же чаю'
for term in term_extractor(text):
print term.normalized
View y-cities.txt
Абагур-Лесной
Абай
Абшвай
Абакумовский
Аббинокмой
Абонкур-сюр-Сей
Абрикосовый
Абый
Абанкай
Абомей
View pagerank.py
# 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 Oct 31, 2013
Distributed Monte Carlo estimation of pi using posix message queue
View pi.c
#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 Aug 30, 2013
map and filter defined using reduce
View reduce.py
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 [])
View mvartree.hs
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 Jun 20, 2013
TextRank algorithm for text summarization.
View textrank.py
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 Dec 17, 2015
Huffman coding algorithm
View huffman.hs
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)
View anagram.hs
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
You can’t perform that action at this time.