Skip to content

Instantly share code, notes, and snippets.

View IaroslavR's full-sized avatar

Iaroslav Russkykh IaroslavR

View GitHub Profile
@IaroslavR
IaroslavR / http-status-codes.md
Created March 8, 2018 00:09 — forked from subfuzion/http-status-codes.md
General REST API HTTP Status Codes

Reference: RFC 2616 - HTTP Status Code Definitions

General

  • 400 BAD REQUEST: The request was invalid or cannot be otherwise served. An accompanying error message will explain further. For security reasons, requests without authentication are considered invalid and will yield this response.
  • 401 UNAUTHORIZED: The authentication credentials are missing, or if supplied are not valid or not sufficient to access the resource.
  • 403 FORBIDDEN: The request has been refused. See the accompanying message for the specific reason (most likely for exceeding rate limit).
  • 404 NOT FOUND: The URI requested is invalid or the resource requested does not exists.
  • 406 NOT ACCEPTABLE: The request specified an invalid format.
@IaroslavR
IaroslavR / examples.py
Last active April 22, 2018 13:51
Examples of readable comprehension formatting from SO
[x.id for x
in self.db.query(schema.allPostsUuid).execute(timeout=20)
if x.type == 'post'
and x.deleted is not False
and ...
and ...]
#-----------------------------------------------------------------
transform = lambda x: x.id
results = self.db.query(schema.allPostsUuid).execute(timeout=20)
condition = lambda x: x.deleted is not False and ... and ...
with open("inFile.txt", 'r') as src, \
open("outFile1.txt", 'w') as out_1, \
open("outFile2.txt", 'w') as out_2:
for line in src.readlines():
out_1.writelines(line)
out_2.writelines(line)
@IaroslavR
IaroslavR / README.md
Created May 7, 2018 17:12
Circular imports in Python 2 and Python 3: when are they fatal? When do they work?

When are Python circular imports fatal?

In your Python package, you have:

  • an __init__.py that designates this as a Python package
  • a module_a.py, containing a function action_a() that references an attribute (like a function or variable) in module_b.py, and
  • a module_b.py, containing a function action_b() that references an attribute (like a function or variable) in module_a.py.

This situation can introduce a circular import error: module_a attempts to import module_b, but can't, because module_b needs to import module_a, which is in the process of being interpreted.

But, sometimes Python is magic, and code that looks like it should cause this circular import error works just fine!

@IaroslavR
IaroslavR / whatsapp.py
Created August 31, 2018 14:30 — forked from deepak3081996/whatsapp.py
send whatsapp messages using python
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
def message(to,message=''):
"""this a simple function to send a whatsapp message to your friends
and group using python and selenium an automated tool to parse the HTML
content and to change the properties.
@IaroslavR
IaroslavR / compile-ffmpeg-nvenc.sh
Created November 5, 2018 04:17
This bash script will compile a static Ffmpeg build with NVENC and VAAPI hardware-accelerated support on Ubuntu in your home directory. You can modify the script to customize the build options as you see fit.
#!/bin/bash
#This script will compile and install a static ffmpeg build with support for nvenc un ubuntu.
#See the prefix path and compile options if edits are needed to suit your needs.
#install required things from apt
installLibs(){
echo "Installing prerequisites"
sudo apt-get update
sudo apt-get -y --force-yes install autoconf automake build-essential libass-dev libfreetype6-dev libgpac-dev \
@IaroslavR
IaroslavR / README.md
Created December 21, 2019 13:11 — forked from M0r13n/README.md
Logging with Loguru in Flask

This is a simple example of how to use loguru in your flask application

Just create a new InterceptHandler and add it to your app. Different settings should be configured in your config file, so that it is easy to change settings.

Logging is then as easy as:

from loguru import logger

logger.info("I am logging from loguru!")

Keybase proof

I hereby claim:

  • I am iaroslavr on github.
  • I am iaro (https://keybase.io/iaro) on keybase.
  • I have a public key ASDG8Z6_Nx-n0Fid9qCMmlQ6HAddpOU7OQwwYOVZlld-rwo

To claim this, I am signing this object:

@IaroslavR
IaroslavR / cherry-pick.sh
Created July 6, 2022 20:10
cherry-pick commit from a different repo
# based on https://stackoverflow.com/q/5120038/4249707
# local source
SRC=../<repo>/.git
COMMIT=<hash>
git --git-dir=${SRC} format-patch -k -1 --stdout ${COMMIT} | git am -3 -k
# remote source
[email protected]:<user>/<repo>.git
NAME=commit-source
@IaroslavR
IaroslavR / db.md
Last active July 29, 2022 16:16
Remote PostgreSQL database without public access connection and maintenance

Connect

DBHOST value must be localhost if db server deployed on HOST or RDS instance hostname if you need to use bastion(HOST) to assess db server deployed in the private subnet.

SOCKET_PATH=/tmp/%r@%h-%p
USER=<ssh user>
HOST=<host to connect>
DBHOST=<db host>
export PGPORT=