Skip to content

Instantly share code, notes, and snippets.

View teror4uks's full-sized avatar

Pavel Sirotkin teror4uks

  • Berlin, Germany
View GitHub Profile
@teror4uks
teror4uks / install_mono.sh
Created May 20, 2016 16:12 — forked from andreazevedo/install_mono.sh
Install mono on centOS 6.x
$ yum install bison gettext glib2 freetype fontconfig libpng libpng-devel libX11 libX11-devel glib2-devel libgdi* libexif glibc-devel urw-fonts java unzip gcc gcc-c++ automake autoconf libtool make bzip2 wget
$ cd /usr/local/src
$ wget http://download.mono-project.com/sources/mono/mono-3.2.8.tar.bz2
$ tar jxf mono-3.2.8.tar.bz2
$ cd mono-3.2.8
@teror4uks
teror4uks / models.py
Last active September 1, 2017 18:31
models.py
# -*- coding: utf-8 -*-
from django.db import models
from itertools import chain
from datetime import datetime, timedelta
class EventManager(models.Manager):
def all(self, *args, **kwargs):
qs = super(EventManager, self).all(*args, **kwargs).filter()
return qs
@teror4uks
teror4uks / centralbank.py
Created September 1, 2017 13:48
CentralBankCurrency
import xml.etree.ElementTree as ET
import urllib3
class Valute:
def __init__(self, node):
self.node = node
for n in node.iter():
if "ID" in n.attrib:
self.id = n.attrib["ID"]
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
@teror4uks
teror4uks / namedtuple_choices.py
Created December 25, 2017 14:13
namedtuple_choices.py
def get_namedtuple_choices(name, choices_tuple):
"""Factory function for quickly making a namedtuple suitable for use in a
Django model as a choices attribute on a field. It will preserve order.
Usage::
class MyModel(models.Model):
COLORS = get_namedtuple_choices('COLORS', (
(0, 'BLACK', 'Black'),
(1, 'WHITE', 'White'),
"""From https://fazle.me/auto-generating-unique-slug-in-django/"""
from django.db import models
from django.utils.text import slugify
class Article(models.Model):
title = models.CharField(max_length=120)
slug = models.SlugField(max_length=140, unique=True)
content = models.TextField()
class SomeMixin:
# Assuming that you want to trigger the task on save:
def save(self, *args, **kwargs):
ret = super().save(*args, **kwargs)
some_task.apply_async((
self.__class__.__name__,
self.pk,
))
return ret
from django.contrib import admin
class InputFilter(admin.SimpleListFilter):
template = 'admin/input_filter.html'
def lookups(self, request, model_admin):
# Dummy, required to show the filter.
return ((),)
def choices(self, changelist):
@teror4uks
teror4uks / README.md
Last active February 22, 2018 09:27
Install Let's Encrypt certificate on new hosts

Description

I using https://github.com/lukas2511/dehydrated for automate updation ssl certs on hosts

Environment

  1. Create new user for handle letsencrypt ssl certs

sudo adduser --system --home /opt/dehydrated dehydrated