Skip to content

Instantly share code, notes, and snippets.

View lucianmarin's full-sized avatar
🐞

Lucian Marin lucianmarin

🐞
View GitHub Profile
@lucianmarin
lucianmarin / get_mentions.py
Last active May 13, 2017 00:20
Return unique mentions from a string.
def get_mentions(text):
limits = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'
words = text.split()
mentions = []
for word in words:
if word.endswith(('.', ',', '!', '?', ':', ';')):
word = word[:-1]
if word.endswith(')'):
word = word[:-1]
if word.startswith('('):
@lucianmarin
lucianmarin / wallis.pi.py
Created April 12, 2020 21:00
Calculate pi
# pip install progressbar2
from progressbar import progressbar
def wallis(n):
pi = 2.
for i in progressbar(range(1, n)):
left = (2. * i) / (2. * i - 1.)
right = (2. * i) / (2. * i + 1.)
pi = pi * left * right
@lucianmarin
lucianmarin / metaclass.py
Last active December 11, 2021 09:44
Alternative to namedtuple and dataclass in Python
class Metaclass:
def asdict(self):
return self.__dict__
def astuple(self):
return tuple(self.__dict__.values())
def fields(self):
return list(self.__dict__.keys())
{
"Afghanistan": [
"Aibak",
"Andkhoy",
"Asadabad",
"Baghlan",
"Balkh",
"Bamyan",
"Baraki Barak",
"Bazarak",