Skip to content

Instantly share code, notes, and snippets.

View dorokhin's full-sized avatar
🎯
Focusing

dorokhin

🎯
Focusing
View GitHub Profile
[uwsgi]
socket = 127.0.0.1:8000
chdir = /usr/share/nginx/projects/app
pythonpath = /usr/bin/python3
#pythonpath = ~/.pyenv/versions/3.4.6/bin/python
wsgi-file = app/wsgi.py
processes = 4
threads = 2
@dorokhin
dorokhin / Django + Ajax dynamic forms .py
Created June 13, 2020 15:57 — forked from goldhand/Django + Ajax dynamic forms .py
Django form with Ajax. A simple Task model that can be updated using a CBV with an AJAX mixin. The view sends post data with ajax then updates the view with a callback to a DetailView with a json mixin.There is an abstract CBV, AjaxableResponseMixin, based on the example form django docs, that is subclassed in the TaskUpdateView CBV. TaskUpdateV…
#models.py
class Task(models.Model):
title = models.CharField(max_length=255)
description = models.TextField()
def __unicode__(self):
return self.title
@dorokhin
dorokhin / django.py
Created April 18, 2020 08:18
Django abstract model hasattr
class BaseModel(models.Model):
def _get_name(self):
if hasattr(self, 'name'):
return str(getattr(self, 'name'))
else:
return str(getattr(self, 'id'))
def __str__(self):
return self._get_name()
@dorokhin
dorokhin / http-benchmark.md
Created April 8, 2020 14:39 — forked from denji/http-benchmark.md
HTTP(S) Benchmark Tools / Toolkit for testing/debugging HTTP(S) and restAPI (RESTful)
@dorokhin
dorokhin / get_tg_user_id.py
Last active March 25, 2020 07:26
Get telegram user_id
import os
import requests
telegram_api_key = os.getenv("TELEGRAM_API_KEY", "")
if __name__ == "__main__":
if ":" in telegram_api_key:
res = requests.post('https://api.telegram.org/bot{}/getUpdates'.format(telegram_api_key))

https://vk.com/foaf.php?id=user_id_here

<!--?xml version="1.0" encoding="WINDOWS-1251"?-->
<html><head></head><body><rdf:rdf xml:lang="ru" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:ya="http://blogs.yandex.ru/schema/foaf/" xmlns:img="http://blogs.yandex.ru/schema/foaf/" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <foaf:person>
    <ya:publicaccess>disallowed</ya:publicaccess>
    <ya:profilestate>active</ya:profilestate>
    <ya:uri ya:primary="yes" rdf:resource="http://vk.com/id123">
    <ya:uri rdf:resource="http://vk.com/screen_name">
@dorokhin
dorokhin / postgres-cheatsheet.md
Created February 19, 2020 09:44 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
import os
from fabric.api import cd, run, prefix, sudo
PROJECT_FOLDER = '/usr/share/nginx/projects/'
REPO_FOLDER = os.path.join(PROJECT_FOLDER, 'site_name.moscow')
ENV_FOLDER = os.path.join(PROJECT_FOLDER, 'env')
ENV_PATH = os.path.join(ENV_FOLDER, 'bin/activate')
@dorokhin
dorokhin / addition.c
Created January 26, 2020 06:57
Load C code (CDLL)
#include <stdio.h>
/*
* gcc -shared -Wl,-soname,adder -o adder.so -fPIC addition.c
*/
int add_int(int, int);
float add_float(float, float);
int add_int(int num1, int num2){
@dorokhin
dorokhin / get-pip-packages.py
Last active December 18, 2019 09:32
Programmatically get list of installed packages
import sys
import subprocess
reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze'])
pip_packages_raw = reqs.decode('utf8').split('\n')
packages_list = []
for package in pip_packages_raw: