Skip to content

Instantly share code, notes, and snippets.

View kmmbvnr's full-sized avatar
💭
#StopPutin #StopWar

Mikhail Podgurskiy kmmbvnr

💭
#StopPutin #StopWar
View GitHub Profile
### Keybase proof
I hereby claim:
* I am kmmbvnr on github.
* I am kmmbvnr (https://keybase.io/kmmbvnr) on keybase.
* I have a public key whose fingerprint is E685 C7A1 645B 1101 B842 9615 CC5D BCAC 89FE 6B7B
To claim this, I am signing this object:
@kmmbvnr
kmmbvnr / quiz.py
Last active June 22, 2016 10:50
Little python quiz
"""
Implement @secret_decorator allows to bypass decorator on base class method
"""
class Base(object):
@secret_decorator
def method(self):
print('base')
@kmmbvnr
kmmbvnr / tox.ini
Last active June 15, 2018 11:50
Even less painless way to launch a script without activating first its virtual environment
[tox]
envlist = py36
skipsdist = True
[testenv]
deps = django==2.0.6
commands = {posargs:./manage.py runserver}
setenv =
PYTHONPATH={toxinidir}
PATH={envdir}/bin:{env:PATH}
@kmmbvnr
kmmbvnr / .gitignore
Last active September 2, 2015 08:13
Divanoparser
*.pyc
*.p12
.tox
settings.py
# Fix no-tty error
# if there a line that only consists of 'mesg n' in /root/.profile, replace it with 'tty -s && mesg n'
config.vm.provision :shell,
:inline => "(grep -q -E '^mesg n$' /root/.profile && sed -i 's/^mesg n$/tty -s \\&\\& mesg n/g' /root/.profile && echo 'Ignore the previous error about stdin not being a tty. Fixing it now...') || exit 0;"
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'socket'
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
@kmmbvnr
kmmbvnr / fields.py
Created March 10, 2016 05:48 — forked from mariocesar/fields.py
Django state field that enforce a workflow path
from collections import namedtuple
from functools import wraps
from itertools import chain
from django.utils.functional import curry
from django.db.models import CharField
class StateField(CharField):
Starts = namedtuple('Starts', ['state'])
class Task(Model):
@contextmanager
def activate(self):
activation = self.flow_task.activation_cls(self.task)
with activation.lock():
yield activation
def start_view(request, start_task):
with start_task.activate() as activation:
@kmmbvnr
kmmbvnr / bigquery.sql
Created July 21, 2016 02:59
Query pypi package download stats
SELECT details.installer.name, COUNT(*)
FROM
TABLE_DATE_RANGE(
[the-psf:pypi.downloads],
TIMESTAMP("20160601"),
TIMESTAMP("20160630")
)
WHERE file.project='django-material'
group by details.installer.name
#!/bin/bash
DWDIR=~/Downloads/`date +%Y-%m-%d`
if [ ! -d $DWDIR ]; then
cd ~/Downloads/ && find -maxdepth 1 -type d -empty -delete
mkdir $DWDIR
unlink ~/Downloads/Current
ln -sf $DWDIR ~/Downloads/Current
fi;