Skip to content

Instantly share code, notes, and snippets.

View 1st's full-sized avatar
🎯
Work smarter, not harder

Anton Danilchenko 1st

🎯
Work smarter, not harder
View GitHub Profile
@1st
1st / PTHPHX.sh
Created August 6, 2014 16:14
Shell script that generates Welcome message to Putin
echo @У-И. *УЙЛO | tr '@-.:%*' ПTHTHX
@1st
1st / django_project_code_sample.py
Created June 3, 2013 14:38
My example of code for Django project
'''
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
@1st
1st / function_decorator.py
Last active December 17, 2015 13:49
My implementation of Python decorators based on functions (not class-based decorator).
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):
@1st
1st / singleton.py
Created March 30, 2013 23:26
Singleton implantation on Python
#!/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
@1st
1st / tests_for_toptal_on_codility.py
Last active May 19, 2022 19:58
My answers for tests on http://codility.com that I passed for company http://toptal.com I use Python language to solve problems.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Test that I passed on codility.com for TopTal company
#
# Task #1
def binary_gap(N):
@1st
1st / get_prime_number.py
Last active December 15, 2015 02:19
Solution for task: http://projecteuler.net/problem=7 By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number?
#!/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: