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/env python | |
# -*- coding: utf-8 -*- | |
def get_prime_number(index): | |
''' | |
Return prime number by given index. | |
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. | |
Args: |
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/env python | |
# -*- coding: utf-8 -*- | |
# | |
# Test that I passed on codility.com for TopTal company | |
# | |
# Task #1 | |
def binary_gap(N): |
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/env python | |
# -*- coding: utf-8 -*- | |
class Singleton(type): | |
def __call__(self, *args, **kwargs): | |
if 'instance' not in self.__dict__: | |
self.instance = super(Singleton, self).__call__(*args, **kwargs) | |
return self.instance | |
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 login_required(function=None, message=None): | |
""" | |
Decorator for views that checks that the user is logged in, | |
or show error page with message. | |
>>> We can use any of this forms of decorator: | |
>>> | |
>>> # 1. without parameters | |
>>> @login_required | |
>>> def my_function(request): |
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
''' | |
My example of code for Django project | |
See also my Open Source project here: https://github.com/1st/django-startup | |
@author Anton Danilchenko <anton.danilchenko@me.com> | |
''' | |
# app_name/urls.py |
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
echo @У-И. *УЙЛO | tr '@-.:%*' ПTHTHX |
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 A(object): | |
def aa(self): | |
print 'in A' | |
return self.__class__.__name__ | |
class B(A): | |
def bb(self): | |
print 'in B' | |
return super(B, self).aa() |
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
""" | |
2015 year calculations. | |
>>> # we missing 32 in this year pow(2,5) | |
>>> pow(2,5) | |
32 | |
>>> 1024+512+256+128+64+0+16+8+4+2+1 | |
2015 | |
>>> bin(2015) | |
'0b11111011111' |
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
# | |
# My settings for python dev env on MacBook. | |
# I use HomeBrew to install python and python3 | |
# cat ~/.profile | |
# | |
# load all completions | |
source /usr/local/etc/bash_completion.d/* | |
# Python VirtualEnv |
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
# 0. install a Postgres | |
# we use HomeBrew for this | |
brew install postgres | |
# init file structure for all databases | |
initdb /usr/local/var/postgres | |
# 1. create new user for a database | |
# 1.1. user without password |
OlderNewer