Skip to content

Instantly share code, notes, and snippets.

Avatar

Pavel Sirotkin teror4uks

  • adjust GmbH
  • Berlin, Germany
View GitHub Profile
@teror4uks
teror4uks / build_docker_nginx_container.txt
Last active May 17, 2018
Docker Nginx configuration for dev enviroment with Django app
View build_docker_nginx_container.txt
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
View upload_moy_sklad.py
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))
View MYSQL_README.md

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 Feb 22, 2018
Install Let's Encrypt certificate on new hosts
View README.md

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

View filters.py
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):
View mixin.py
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
View example_uniuq_slug.py
"""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()
View 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'),
View .bashrc
# ~/.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