Skip to content

Instantly share code, notes, and snippets.

View btseytlin's full-sized avatar
👁️‍🗨️
https://t.me/boris_again

Boris Tseitlin btseytlin

👁️‍🗨️
https://t.me/boris_again
View GitHub Profile
import numpy as np
import math
import csv
input_file = 'output_5k.csv'
#N;ComparedIDs;Name;A;ADV;ADVPRO;ANUM;APRO;COM;CONJ;INTJ;NUM;PART;PR;SPRO;V;S;Duplicate;
#'i8, object, i4, i4, i4, i4, i4,i4, i4, i4, i4, i4,i4, i4, i4, i4,i4,i4')
#"i8,S30,i4, i4, i4, i4, i4,i4, i4, i4, i4, i4,i4, i4, i4, i4,i4,i4,i4"
#data = np.loadtxt(input_file, delimiter=';', usecols=(2,4,5,6,7,8,9,10,11,12,13,14,15,16,17),skiprows=1, dtype=int)
import sys
def get_operations(diff, cookies):
operations = 0
for i, c in enumerate(cookies):
x = cookies[i]-diff
while x > 0:
operations+= x // 5
x = x % 5
@btseytlin
btseytlin / kmeansExample.py
Created May 31, 2017 06:23 — forked from iandanforth/kmeansExample.py
A pure python implementation of K-Means clustering. Optional cluster visualization using plot.ly.
#############################################################################
# Full Imports
import math
import random
"""
This is a pure Python implementation of the K-Means Clustering algorithmn. The
original can be found here:
http://pandoricweb.tumblr.com/post/8646701677/python-implementation-of-the-k-means-clustering
class HungerMeter(object): #a descriptor for hunger
def __init__(self):
self._hunger = 0
def __get__(self, instance, owner):
return instance._hunger
def __set__(self, instance, hunger):
if hunger < 0:
hunger = 0
#We have a linux machine and a windows machine
#We are testing their capabilities, and we need to verify both can send emails and telnet messages
#We need to send a notification to another machine from both linux and windows machines
message = "Automated notification: Hello!"
target_mail = "[email protected]"
target_telnet = "telnet_address"
#We have different notificators and different platforms, so it makes sense to separate them
class WindowsEmailNotificator:
@btseytlin
btseytlin / visitor.py
Created June 20, 2017 05:52
Паттерн проектирования Visitor
# -*- coding: utf-8 -*-
"""
Пусть есть три типа мобильных девайсов - Iphone, Android, Windows mobile
Все девайсы имеют Bluetooth
Пусть bluetooth радио могут быть от одного из двух производителей - intel и broadcom
Пусть Intel радио имеют не такой интерфейс, как Broadcom радио.
#Open/closed пинцип.
#Формулируется: Классы открыты для расширения, но закрыты для модификации.
#Пример (абсолютно непрактичный). Пусть у нас есть игра, типа веселая ферма для задротов.
#Есть животные, наследующиеся от базового класса Animal. Например Dog, Cat, Horse.
#Животных надо кормить. Поэтому есть кормушка класса Feeder, которая отвечает за кормление животных.
#Каждое животное кормится отдельным видом корма.
#Пример когда принцип не соблюдается
class Animal:
def is_palindrome(text):
if len(text) < 2:
return False
return text[:len(text)//2] == text[len(text)//2:][::-1]
def remove_palindromes(text):
if not text or len(text) < 2:
return text
out_text = text
def get_palindrome_bounds(text, palindrome_index):
left = palindrome_index
right = palindrome_index+1
while (text[left] == text[right]): #move outwards until we reach the end/start of string or the string between left and right stops being a palindrome
if left -1 >= 0 and right+1 < len(text) and text[left-1] == text[right+1]:
left = left-1
right = right + 1
else:
break
return left, right
FROM gliderlabs/alpine:3.4
RUN \
apk-install \
curl \
openssh-client \
python \
py-boto \
py-dateutil \
py-httplib2 \