Skip to content

Instantly share code, notes, and snippets.

View slavama's full-sized avatar

Slava slavama

  • Asia/Krasnoyarsk
View GitHub Profile
@slavama
slavama / eslint.js
Last active March 11, 2017 16:38
My webpack config
module.exports = {
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true,
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module",
@slavama
slavama / create-django-project.sh
Last active March 15, 2017 00:52
Simple shell script for django project creation
#!/usr/bin/env bash
#
# Simple shell script for django project creation
# Edit variables section and run: create_django_app.sh projectname
#
NAME=$1
DOMAIN="$NAME.dev"
@slavama
slavama / make_repo.sh
Created April 3, 2017 03:40
Create remote private repository
#!/bin/bash
PROJECT=$1
REPO_USER=myusername
REPO_API_URL=https://api.bitbucket.org/1.0/repositories/
PROJECTS_DIR=/home/username/projects
APP_DIR="$PROJECTS_DIR/$PROJECT"
curl --user $REPO_USER $REPO_API_URL --data name=$PROJECT --data is_private='true' --data scm='git'
@slavama
slavama / tar.py
Created September 12, 2018 08:20
tar.gz archiving in python
import os
import tarfile
from contextlib import closing
@slavama
slavama / settings.py
Created October 9, 2018 07:27
django yandex pdd
EMAIL_HOST = 'smtp.yandex.ru'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = '[email protected]'
EMAIL_USE_TLS = True
@slavama
slavama / gost_engine.sh
Created January 23, 2019 11:09 — forked from shadz3rg/gost_engine.sh
Настройка ГОСТ OpenSSL под Ubuntu 18.04
# Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-36-generic x86_64)
# (из коробки) OpenSSL 1.1.0g 2 Nov 2017
# (из коробки) curl 7.58.0 (x86_64-pc-linux-gnu)
# PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )
# Компилим GOST-engine
sudo apt install cmake libssl-dev
git clone --branch=openssl_1_1_0 https://github.com/gost-engine/engine.git gost-engine/engine
cd gost-engine/engine
cmake .
@slavama
slavama / vars.py
Created February 13, 2019 07:06
Установка переменной в шаблоне DJANGO
from django import template
register = template.Library()
class SetVarNode(template.Node):
def __init__(self, var_name, var_value):
self.var_name = var_name
self.var_value = var_value
@slavama
slavama / models.py
Created February 13, 2019 07:10
Расширить менеджер модели в DJANGO
class DocumentQuerySet(models.QuerySet):
def pdfs(self):
return self.filter(file_type='pdf')
def smaller_than(self, size):
return self.filter(size__lt=size)
class Document(models.Model):
name = models.CharField(max_length=30)
size = models.PositiveIntegerField(default=0)
@slavama
slavama / urls.js
Created August 31, 2019 12:21
React-router reverse
import pathToRegexp from 'path-to-regexp';
export const reverse = (path, kwargs={}) => {
const toPath = pathToRegexp.compile(path);
return toPath(kwargs);
};
@slavama
slavama / documents.js
Created September 26, 2019 11:26
Методы валидации ИНН и СНИЛС для jquery.validate.js
$.validator.addMethod("inn", function (value, element) {
var multipliers = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8],
inn = value.split(''), i, j, ch = [0, 0, 0];
for (i = 0; i < 12; i++)
for (j = 0; j < 3; j++)
if (multipliers[i + j])
ch[j] = ch[j] + inn[i] * multipliers[i + j];
if (inn.length == 10)
return inn[9] == ch[2] % 11 % 10;
else if (inn.length == 12)