Skip to content

Instantly share code, notes, and snippets.

View sashadev-sky's full-sized avatar

sashadev-sky

  • New York, NY
View GitHub Profile
0 = Success
1 = Operation not permitted
2 = No such file or directory
3 = No such process
4 = Interrupted system call
5 = Input/output error
6 = No such device or address
7 = Argument list too long
8 = Exec format error
9 = Bad file descriptor
function bycache() {
find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf
}
project
│   README.md
│   file001.txt    
│
└───folder1
│   │   file011.txt
│   │   file012.txt
│   │
│ └───subfolder1
@sashadev-sky
sashadev-sky / 00_relative_import_resolution.py
Last active April 25, 2022 15:42
"ImportError: attempted relative import with no known parent package" and its sibling "ValueError: attempted relative import beyond top-level package"
print('__file__={0:<35} | __name__={1:<20} | __package__={2:<20}'.format(
__file__, __name__, str(__package__)))
@sashadev-sky
sashadev-sky / blueprint.py
Created March 31, 2021 16:46 — forked from brenj/blueprint.py
Store application configuration in a Flask blueprint.
@blueprint.record_once
def record_params(state):
"""Store app.config in blueprint when blueprint is registered on app."""
app = state.app
blueprint.config = {key: value for key, value in app.config.iteritems()}
@sashadev-sky
sashadev-sky / render_json.py
Created March 27, 2021 05:01 — forked from nerevar/render_json.py
Pretty print json in jupyter/ipython notebook
import json
import uuid
from IPython.display import display_javascript, display_html, display
class RenderJSON(object):
def __init__(self, json_data):
if isinstance(json_data, dict) or isinstance(json_data, list):
self.json_str = json.dumps(json_data)
else:
self.json_str = json_data
@sashadev-sky
sashadev-sky / launch.json
Created March 27, 2021 04:18
fix error couldn't set PYTHONPATH of undefined in VSCode
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
@sashadev-sky
sashadev-sky / get_exceptions_tree.py
Last active March 23, 2021 20:32
Useful exception tree reference for Python3
def print_exceptions_tree(exception_class, level=0):
if level > 1:
print(" |" * (level - 1), end="")
if level > 0:
print(" +---", end="")
print(exception_class.__name__)
for subclass in exception_class.__subclasses__():
print_exceptions_tree(subclass, level + 1)
import uuid
import csv
def my_random_string(string_length=10):
"""Returns a random string of length string_length."""
random = str(uuid.uuid4()) # Convert UUID format to a Python string.
random = random.upper() # Make all characters uppercase.
random = random.replace("-", "") # Remove the UUID '-'.
return random[0:string_length] # Return the random string.
@sashadev-sky
sashadev-sky / jupyter_fun.ipynb
Last active December 10, 2020 07:06
Pretty Print All Cell’s Outputs (and not just the last output of the cell)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.