Skip to content

Instantly share code, notes, and snippets.

View lucianmarin's full-sized avatar
🐞

Lucian Marin lucianmarin

🐞
View GitHub Profile
{
"Afghanistan": [
"Aibak",
"Andkhoy",
"Asadabad",
"Baghlan",
"Balkh",
"Bamyan",
"Baraki Barak",
"Bazarak",
@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())
@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 / tohsp.py
Created April 13, 2017 11:24
HSP color space was created Darel Rex Finley http://alienryderflex.com/hsp.html
#!/usr/bin/python
import math
import sys
print sys.argv[1]
print sys.argv[2]
print sys.argv[3]
R = float(sys.argv[1])
def qsort(list):
if list == []:
return []
pivot = list[0]
l = qsort([x for x in list[1:] if x < pivot])
u = qsort([x for x in list[1:] if x >= pivot])
return l + [pivot] + u
@lucianmarin
lucianmarin / parser.py
Last active May 13, 2017 00:10
Sublevel’s text to HTML parser.
from django.utils.safestring import mark_safe
def parser(text):
''' Convert plain text to HTML '''
limits = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'
digits = '0123456789'
# unicode xml safe
text = text.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
# replace &nbsp; (160) with space (32)
text = text.replace(chr(160), chr(32))
@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 / index.js
Last active July 6, 2016 09:43
Create amp from url or html
#!/usr/bin/env node
var program = require('commander'),
read = require('node-readability'),
format = require('distro-mic').format;
program
.version('1.0.0')
.option('-u, --url [type]', 'Input article URL')
.option('-h, --html [type]', 'Input HTML code')
.parse(process.argv);
@lucianmarin
lucianmarin / settings.py
Last active April 1, 2016 11:25
/?debug DRF endpoints
# pip install django-debug-toolbar
# /api/creatives/?format=json&debug
from django.http import HttpResponse
import json
INSTALLED_APPS += ('debug_toolbar',)
MIDDLEWARE_CLASSES += (
'debug_toolbar.middleware.DebugToolbarMiddleware',
@lucianmarin
lucianmarin / .vimrc
Last active October 3, 2015 09:51
vim config ~/.vimrc
filetype plugin on
set omnifunc=syntaxcomplete#Complete
set wrap
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set softtabstop=4
set smarttab
set expandtab