Skip to content

Instantly share code, notes, and snippets.

View slavama's full-sized avatar

Slava slavama

  • Asia/Krasnoyarsk
View GitHub Profile
@slavama
slavama / admin.py
Created March 28, 2022 07:38 — forked from herotux/admin.py
django rest api framework session auth example
from django.contrib import admin
from .models import User
admin.site.register([User])
@slavama
slavama / copy_key.sh
Last active December 16, 2021 03:46
Copy authorized key to remote server for login without password
cat ~/.ssh/id_rsa.pub | ssh REMOTE_USER@REMOTE_IP "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
// ssh-copy-id REMOTE_USER@REMOTE_IP
@slavama
slavama / gist:a743ce9fafa17d7642a21ed92f6f3338
Created January 24, 2021 12:44
esp8266 weather station
#include <ESP8266WiFi.h>
#include <TM1637Display.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFiMulti.h>
#include "DHTesp.h"
const char* ssid = "HUAWEI-E8372-26A6";//put your wifi ssid here
const char* password = "***";//put your wifi password here
const int CLK = D2; //Set the CLK pin connection to the display
@slavama
slavama / bulk_update.sql
Created November 12, 2019 15:23
postgresql bulk update
CREATE TABLE billing.mytable(id integer, name text);
INSERT INTO billing.mytable VALUES(1, '1');
INSERT INTO billing.mytable VALUES(2, '2');
INSERT INTO billing.mytable VALUES(3, '3');
UPDATE billing.mytable
SET name = Q.name
FROM (
SELECT (value->>0)::integer AS id, (value->>1)::decimal AS name
@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)
@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 / 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 / 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 / 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 / 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