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 / build_docker_nginx_container.txt
Last active May 17, 2018 09:16
Docker Nginx configuration for dev enviroment with Django app
docker run --name rezerv-nginx \
-v /path/to/nginx/config/nginx.conf:/etc/nginx/conf.d/app.conf \
-v /path/to/django/project/folder/:/var/www/html/ \
-v /path/to/uwsgi/socks/folder/:/var/run/ \
-v /path/to/log/folder/:/var/log/nginx/ -d -p 8080:8080 nginx:latest
import requests
MS_STOCK_URL = 'https://online.moysklad.ru/exchange/rest/stock/json'
MOD_TRUE = 'showConsignments=true'
ALL_STOCK = 'stockMode=ALL_STOCK'
MS_USER = 'user'
MS_PASSWORD = 'pass'
with_mods = '{}?{}&{}'.format(MS_STOCK_URL, MOD_TRUE, ALL_STOCK)
r = requests.get(with_mods, auth=(MS_USER, MS_PASSWORD))
@teror4uks
teror4uks / MYSQL_README.md
Last active April 28, 2018 11:14
Mysql reminder

Create db in utf-8 encoding

CREATE DATABASE <db_name> CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Recovery backup from archive

tar -xzOf <archive_name>.tar.gz | mysql -u root -p <db_name>
@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

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):
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 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()
@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'),
# ~/.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