This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2' | |
services: | |
ansible: | |
build: . | |
volumes: | |
- ./:/ansible/exploitation/ | |
network_mode: host |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM gliderlabs/alpine:3.4 | |
RUN \ | |
apk-install \ | |
curl \ | |
openssh-client \ | |
python \ | |
py-boto \ | |
py-dateutil \ | |
py-httplib2 \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Open/closed пинцип. | |
#Формулируется: Классы открыты для расширения, но закрыты для модификации. | |
#Пример (абсолютно непрактичный). Пусть у нас есть игра, типа веселая ферма для задротов. | |
#Есть животные, наследующиеся от базового класса Animal. Например Dog, Cat, Horse. | |
#Животных надо кормить. Поэтому есть кормушка класса Feeder, которая отвечает за кормление животных. | |
#Каждое животное кормится отдельным видом корма. | |
#Пример когда принцип не соблюдается | |
class Animal: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Пусть есть три типа мобильных девайсов - Iphone, Android, Windows mobile | |
Все девайсы имеют Bluetooth | |
Пусть bluetooth радио могут быть от одного из двух производителей - intel и broadcom | |
Пусть Intel радио имеют не такой интерфейс, как Broadcom радио. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################# | |
# 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 |