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
def batchnorm_forward(x, gamma, beta, bn_param):
"""
Forward pass for batch normalization.
During training the sample mean and (uncorrected) sample variance are
computed from minibatch statistics and used to normalize the incoming data.
During training we also keep an exponentially decaying running mean of the
mean and variance of each feature, and these averages are used to normalize
data at test-time.
version: '2'
services:
ansible:
build: .
volumes:
- ./:/ansible/exploitation/
network_mode: host
FROM gliderlabs/alpine:3.4
RUN \
apk-install \
curl \
openssh-client \
python \
py-boto \
py-dateutil \
py-httplib2 \
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
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
#Open/closed пинцип.
#Формулируется: Классы открыты для расширения, но закрыты для модификации.
#Пример (абсолютно непрактичный). Пусть у нас есть игра, типа веселая ферма для задротов.
#Есть животные, наследующиеся от базового класса Animal. Например Dog, Cat, Horse.
#Животных надо кормить. Поэтому есть кормушка класса Feeder, которая отвечает за кормление животных.
#Каждое животное кормится отдельным видом корма.
#Пример когда принцип не соблюдается
class Animal:
@btseytlin
btseytlin / visitor.py
Created June 20, 2017 05:52
Паттерн проектирования Visitor
# -*- coding: utf-8 -*-
"""
Пусть есть три типа мобильных девайсов - Iphone, Android, Windows mobile
Все девайсы имеют Bluetooth
Пусть bluetooth радио могут быть от одного из двух производителей - intel и broadcom
Пусть Intel радио имеют не такой интерфейс, как Broadcom радио.
#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:
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
@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