Skip to content

Instantly share code, notes, and snippets.

View comalex's full-sized avatar

Oleksii Stupak comalex

View GitHub Profile
@comalex
comalex / models.py
Created October 8, 2016 13:30
Django user
class CustomUserManager(BaseUserManager):
def _create_user(self, email, password,
is_staff, is_superuser, **extra_fields):
"""
Creates and saves a User with the given email and password.
"""
now = timezone.now()
if not email:
raise ValueError('The given email must be set')
@comalex
comalex / aiohttp_devtools_error.py
Created June 29, 2017 18:11
aiohttp_devtools error traceback
>>> manage.py
from aiohttp_devtools.cli import cli
cli()
>>>
Error:
python3.6 manage.py runserver
[21:01:48] pre-check enabled, checking app factory
[21:01:48] Starting dev server at http://localhost:8000 ●
@comalex
comalex / PythonUnitTestCheatSheet.md
Last active July 16, 2017 14:03 — forked from mogproject/PythonUnitTestCheatSheet.md
Python unittest Cheat Sheet

Python unittest Cheat Sheet

Skeleton

@comalex
comalex / mock.md
Last active February 12, 2020 07:41
Mock python cheatsheet

Python unittest.mock Cheat Sheet

Basic usage

mock.Mock()
mock.MagicMock()

Asserts

assert_called_with: This method asserts that the last call was made with the given parameters

@comalex
comalex / google_ping.py
Last active August 9, 2017 14:34
Ping google use all available ips on the current machine
"""
Eсть сервер с несколькими айпи на линукс. у сервера 4 айпи. надо написать скрипт на питон 3,
который устанавливает в 4х потоках (каждый поток использует отдельный айпи), соединение с гугл.ком
"""
"""
pip3 install -r requirements.txt
"""
import logging
@comalex
comalex / Dockerfile
Last active August 17, 2017 22:13
Set up MS SQL 2005 on MAC with virtual box and docker
FROM lbosqmsft/mssql-python-pyodbc
RUN apt-get install -y freetds-dev
RUN apt-get install -y tdsodbc
EXPOSE 80
ADD . /app
WORKDIR /app
RUN pip install -r requirements.txt
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
<!-- Nmodes start -->
<script data-wpfc-render="true" defer src="https://bot1.nmodes.com/v1/widget?api_key=7YJEE6nrZbDRolKBvTwi4pF4"></script>
<!-- Nmodes end -->
@comalex
comalex / premisses.js
Created September 20, 2019 12:31
Webhook example
var request = require("request");
var options = { method: 'POST',
url: 'https://bot1.nmodes.com/bot/api/v1/webhook',
headers:
{
Authorization: 'Bearer YOURTOKEN',
'Content-Type': 'application/json' },
body:
{ user:
@comalex
comalex / premises.js
Last active September 25, 2019 13:42
CASE 1
{
"user": {
"id": 1,
"first_name": "Ben",
"last_name": "Chung",
"address": "Baker Street, London, NW1 6XE"
},
"responseId": "312f4-094f4-12ddf",
"queryTask": [
{
@comalex
comalex / webhook.js
Last active September 27, 2019 21:16
case 1 premises
{
"taskId": 123,
"userId": 1,
"task": "maintenance issue",
"details": {
"activity": "leak",
"location": "suite #4",
"problem source": "room105"
},
"status": "resolved",