This file contains 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
# How to find a missing number from a list? | |
>>> a=[1,2,3,4,5,7,8,9,10] | |
>>> sum(xrange(a[0],a[-1]+1)) - sum(a) | |
6 | |
def is_matched(expression): | |
""" | |
Finds out how balanced an expression is. | |
With a string containing only brackets. |
This file contains 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
# --- iterators --- | |
# Если у объекта есть методы __iter__() __next__() значит он является итератором | |
class MyIter(object): | |
def __init__(self, start, stop): | |
self._current = start | |
self._stop = stop | |
def __iter__(self): |
This file contains 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 roman_to_arabic(line): | |
roman_numerals = { | |
'I': 1, | |
'V': 5, | |
'X': 10, | |
'L': 50, | |
'C': 100, | |
'D': 500, | |
'M': 1000 |
This file contains 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 Phonebook: | |
def __init__(self): | |
self.entries = {} | |
def add(self, name, number): | |
self.entries[name] = number | |
def lookup(self, name): | |
return self.entries[name] | |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import subprocess | |
def output(color, message='empty message'): | |
colors = { | |
'blue' : '\033[94m', | |
'green' : '\033[92m', |
This file contains 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
import requests | |
from bs4 import BeautifulSoup as bs | |
import sys | |
def get_track_status(track_number): | |
base_url = 'http://novaposhta.ua/ru/tracking/?cargo_number=' | |
headers = {'Accept-Language':'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3'} | |
data = requests.get(base_url + track_number, headers=headers) | |
data.encoding = 'utf-8' | |
soup = bs(data.text) |
This file contains 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
import psutil | |
for proc in psutil.process_iter(): | |
try: | |
proc = proc.as_dict(attrs=['pid', 'name']) | |
except psutil.NoSuchProcess: | |
pass | |
else: | |
if proc['name'] == 'firefox': |
This file contains 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 decorate(func): | |
... print u"Декорируем %s..." % func.__name__, | |
... def wrapped(*args, **kwargs): | |
... print "Вызываем обёрнутую функцию с аргументами:", args | |
... return func(*args, **kwargs) | |
... print u"выполнено!" | |
... return wrapped | |
import logging |
This file contains 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
for i in `mysql -uroot porta-configurator -sse "select ip from Servers"` | |
do | |
h=`mysql -uroot porta-configurator -sse "select Name from Servers where IP='$i'"` | |
echo -e "\n====== $h $i ======\n" | |
rsh_porta.sh $i ' | |
red=`echo -en "\e[31m"` | |
green=`echo -en "\e[32m"` | |
normal=`echo -en "\e[0m"` | |
lightyellow=`echo -en "\e[93m"` | |
if [ $(grep -qi gateway /etc/sysconfig/network; echo "$?") -eq 0 ] |
NewerOlder