Skip to content

Instantly share code, notes, and snippets.

View ZoranPandovski's full-sized avatar
:octocat:

Zoran Pandovski ZoranPandovski

:octocat:
View GitHub Profile
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@ZoranPandovski
ZoranPandovski / pypi_queries
Created February 25, 2020 12:51
PYPI downloads statistic from Google Big Query
#MONTHLY PYPI PACKAGE DOWNLOADS
SELECT
COUNT(*) AS num_downloads,
SUBSTR(_TABLE_SUFFIX, 1, 6) AS `day`
FROM `the-psf.pypi.downloads*`
WHERE
file.project = 'mindsdb'
-- Only query the last 6 months of history
AND _TABLE_SUFFIX
BETWEEN FORMAT_DATE(
@ZoranPandovski
ZoranPandovski / object_pool.py
Created October 12, 2018 13:29
Simple object pool example in Python
class Pool:
'''Manage pool objects'''
def __init__(self, size):
self._objects = [PoolObject() for i in range(size)]
def get_object(self):
return self._objects.pop()
@ZoranPandovski
ZoranPandovski / prototype.py
Created October 12, 2018 12:43
Prototype design pattern in python
class Prototype(object):
value = 'default'
def clone(self, **attrs):
"""Clone a prototype and update dictionary"""
obj = self.__class__()
obj.__dict__.update(attrs)
return obj
@ZoranPandovski
ZoranPandovski / builder.py
Last active October 9, 2018 12:48
Builder design pattern example
class Director():
'''Controls creation of final product '''
def __init__(self, builder):
self._builder = builder
def create_house(self):
self._builder.create_new_house()
self._builder.add_basement()
self._builder.add_rooms()
self._builder.add_roof()
@ZoranPandovski
ZoranPandovski / singleton.py
Last active October 8, 2018 16:39
Singleton dp in Python
class Singleton(type):
def __init__(cls, name, bases, attrs, **kwargs):
super().__init__(name, bases, attrs)
cls._instance = None
def __call__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super().__call__(*args, **kwargs)
return cls._instance
@ZoranPandovski
ZoranPandovski / singleton_borg.py
Last active October 8, 2018 15:48
Singleton behavior using Borg pattern
class Borg(object):
__shared_state = {}
def __init__(self):
self.__dict__ = self.__shared_state
class Singleton(Borg):
pass
if __name__ == '__main__':
@ZoranPandovski
ZoranPandovski / abstract_factory.py
Created October 7, 2018 16:41
Abstract Factory in python
class Car:
def drive(self):
print("Starting the Car engine!")
class Bus:
def drive(self):
print("Starting the Bus engine!")
@ZoranPandovski
ZoranPandovski / factory.py
Created October 7, 2018 15:59
Factory method pattern in Python
class Car:
def __init__(self, name, capacity):
self._name = name
self._capacity = capacity
def drive(self):
print("Starting the Car engine!")
class Bus:
def __init__(self, name, capacity):
gdpr_cc = ["AT", "BE", "BG", "CY", "CH", "CZ", "DE", "DK", "EE", "ES", "FI", "FR",
"GB", "GR", "HR", "HU", "IE","IS", "IT","LI", "LT", "LU", "LV", "MT", "NL","NO",
"PL", "PT", "RO", "SE", "SI", "SK"]
#EU and EFTA Country codes