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
""" | |
Few ways to calculate factorial of the number. | |
For my article: http://pavdmyt.com/digging-around-factorial-function/ | |
""" | |
import math as m | |
def fact(x): | |
""" | |
Weird factorial function implementation |
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
tuples = [(1, 2), (3, 4, 5), (6, 7, 8, 9)] | |
for *_, last in tuples: | |
print(last) | |
# Prints: 2, 5, 9 |
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 python3 | |
# -*- coding: utf-8 -*- | |
""" | |
A script to scrape data and stats about Formula 1 teams from Wikipedia pages. | |
Results are exported into a CSV file. | |
""" | |
import logging | |
from datetime import datetime |
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
""" | |
Is analogous to @reify | |
Borrowed from here: https://github.com/aio-libs/yarl/blob/master/yarl/__init__.py | |
Topic references: | |
https://www.reddit.com/r/learnpython/comments/2oqusj/pyramids_reify_descriptor_could_it_be_simplified/ | |
http://www.gghh.name/dibtp/2013/06/18/caching-in-python-with-a-descriptor-and-a-decorator.html | |
""" | |
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
""" | |
Some implementations of infinite / endless for loops in Python. | |
No practical applications, just pure theoretical interest :) | |
C/C++ example: | |
for (;;) {} | |
src: https://stackoverflow.com/questions/5737196/an-expression-for-an-infinite-generator | |
""" | |
import itertools |
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 | |
""" | |
Remove all packages from requirements-dev.txt | |
except of listed in PACKAGES. | |
""" | |
import os | |
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
# -*- coding: utf-8 -*- | |
""" | |
A daemon that monitors files mtimes and automaticaly syncs it | |
with remote if files have changed. | |
How to use: | |
~~~~~~~~~~~ | |
1. $ python syncer.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
# -*- coding: utf-8 -*- | |
""" | |
Print all valid IPv4 netmasks in dot-decimal notation. | |
Netmask reference chart: | |
http://unixwiz.net/techtips/netmask-ref.html | |
""" | |
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
Logical CPUs: 4 | |
Value to calculate: 1e+06 | |
--- | |
SimpleFactFast -- elapsed time: 2.909772092s | |
HalfIterFact -- elapsed time: 1m8.50245915s | |
SimpleFactIter -- elapsed time: 1m57.486627904s | |
ConcFactIter :: workers 1 -- elapsed time: 1m54.401843303s | |
ConcFactIter :: workers 2 -- elapsed time: 42.335188303s |
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
""" | |
Some func problems | |
~~~~~~~~~~~~~~~~~~ | |
Provide your solutions and run this module. | |
""" | |
def add(a, b): |
OlderNewer