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
#!/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 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
#!/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 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
#!/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 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 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 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
''' | |
My example of code for Django project | |
See also my Open Source project here: https://github.com/1st/django-startup | |
@author Anton Danilchenko <[email protected]> | |
''' | |
# app_name/urls.py |
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
echo @У-И. *УЙЛO | tr '@-.:%*' ПTHTHX |
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 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 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
""" | |
Demonstration how to execute Python code parallel with `yield` keyword. | |
Need Python 3.3 or above to use "return" in generator function. | |
This experiment is a step to implement Node.JS-like parallelism into Python web framework WebPages <https://github.com/webpages/webpages> | |
""" | |
def query_db(): | |
return "result from database" |
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
""" | |
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 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
# | |
# 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 |
OlderNewer