Skip to content

Instantly share code, notes, and snippets.

View sprytnyk's full-sized avatar
๐Ÿช–
Fighting for the bright future of ๐Ÿ‡บ๐Ÿ‡ฆ

Vladyslav Krylasov sprytnyk

๐Ÿช–
Fighting for the bright future of ๐Ÿ‡บ๐Ÿ‡ฆ
View GitHub Profile
@sprytnyk
sprytnyk / .editorconfig
Created October 19, 2018 12:15
A basic edit config.
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
@sprytnyk
sprytnyk / pointers_and_references.cpp
Last active July 29, 2019 09:07
Differences between pointers & references from C++ perspective.
#include <iostream>
using namespace std;
int main() {
/*
* References are often confused with pointers but three major
* differences between references and pointers are:
* - You cannot have NULL references. You must always be able to assume
* that a reference is connected to a legitimate piece of storage.
@sprytnyk
sprytnyk / rnp.cpp
Created July 29, 2019 09:39
Pointers & references in Python & CPP (rough analogues).
#include <iostream>
using namespace std;
int main() {
// References in work.
int x(0);
int &ref = x;
x = 10;
import doctest
import unittest
# Paths to one's Python modules
from app import models, views
def test_doctest_suit():
test_suit = unittest.TestSuite()
test_suit.addTest(doctest.DocTestSuite(models))
.
โ”œโ”€โ”€ app
โ”‚ย ย  โ”œโ”€โ”€ __init__.py
โ”‚ย ย  โ”œโ”€โ”€ models.py
โ”‚ย ย  โ””โ”€โ”€ views.py
โ””โ”€โ”€ tests
โ”œโ”€โ”€ __init__.py
โ”œโ”€โ”€ test_models.py
โ””โ”€โ”€ test_views.py
@sprytnyk
sprytnyk / pytest_output.py
Created December 22, 2019 10:42
An example of pytest output that shows doctests and unittests failures.
==================================================================== test session starts =====================================================================
platform linux -- Python 3.6.9, pytest-5.3.2, py-1.8.0, pluggy-0.13.1
rootdir: /home/vald/Projects/personal/doctests_discovery
collected 4 items
tests/test_models.py . [ 25%]
tests/test_package_doctests.py F [ 50%]
tests/test_views.py .F [100%]
========================================================================== FAILURES ==========================================================================
@sprytnyk
sprytnyk / create-pdbpp-config.sh
Created March 16, 2020 19:30
The script creates a file in a home directory of a user to be used by pdb++ to eliminate a truncated output.
#!bin/bash
cat > ~/.pdbrc.py <<EOF
import pdb
class Config(pdb.DefaultConfig):
sticky_by_default = True
truncate_long_lines = False
EOF
@sprytnyk
sprytnyk / install-postman.sh
Last active November 23, 2023 12:49
Install Postman on Ubuntu.
#!/bin/bash
cd /tmp || exit
echo "Downloading Postman ..."
wget -q https://dl.pstmn.io/download/latest/linux?arch=64 -O postman.tar.gz && \
tar -xzf postman.tar.gz && \
rm postman.tar.gz
echo "Installing to ~/.local/opt..."
test -d ~/.local/opt || mkdir ~/.local/opt
test -d ~/.local/opt/Postman && rm -rf ~/.local/opt/Postman
@sprytnyk
sprytnyk / systemd-resolved-switch.sh
Created April 9, 2020 12:38
A simple script to turn on/off systemd-resolved.service from /etc/openvpn/update-resolv-conf.
#!/usr/bin/env bash
STATUS="$(sudo systemctl status systemd-resolved.service)"
# Stops the service if systemd-resolv.service is running.
if echo "${STATUS}" | grep -q "running"
then
sudo systemctl stop systemd-resolved.service > /dev/null 2>&1
if sudo systemctl status systemd-resolved.service | grep -q "inactive"
then
@sprytnyk
sprytnyk / mock_instance_method.py
Created April 11, 2020 15:47
How to mock an instance method.
from unittest.mock import patch
from core import utils
# specify what should be patched
patcher = patch('core.utils.PythonFilesLookUp')
# attach the original class to the variable because it will be modified
# when the patcher will start
original = utils.PythonFilesLookUp
# start the patcher and mock the class, this will produce a mock