This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
####################################################################### | |
# This is a helper script that keeps snapraid parity info in sync with | |
# your data and optionally verifies the parity info. Here's how it works: | |
# 1) Shuts down configured services | |
# 2) Calls diff to figure out if the parity info is out of sync. | |
# 3) If parity info is out of sync, AND the number of deleted or changed files exceed | |
# X (each configurable), it triggers an alert email and stops. (In case of | |
# accidental deletions, you have the opportunity to recover them from |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ruamel.yaml as yaml | |
with open("example.yaml") as stream: | |
try: | |
print(yaml.load(stream)) | |
except yaml.YAMLError as exc: | |
print(exc) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Exclude folder from tar | |
$ tar --exclude='./folder' --exclude='./upload/folder2' -zcvf /backup/filename.tgz . | |
# Make sure to put --exclude before the source and destination items. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Creation of virtualenv: | |
python3 -m venv <desired-path> | |
# Activate the virtualenv: | |
source <desired-path>/bin/activate | |
# Deactivate the virtualenv: | |
deactivate | |
# Install packages with pip3 | |
pip install Cython==0.27.3 | |
pip install kivy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Open file | |
with open(streams_file, 'r') as f: | |
# Read lines and strip '\n' new line character | |
streams = [x.strip('\n') for x in f.readlines()] # List of streams |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is extended slice syntax. It works by doing [begin:end:step] - by leaving begin and end off and specifying a step of -1, it reverses a string. | |
>>> 'hello world'[::-1] | |
'dlrow olleh' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To return multiple values from a function, simply return a tuple. For example: | |
>>> def myfun(): | |
... return 1, 2, 3 | |
... | |
>>> a, b, c = myfun() | |
>>> a | |
1 | |
>>> b | |
2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# It allows you to provide a default value if the key is missing: | |
dictionary.get("bogus", default_value) | |
# returns default_value (whatever you choose it to be), whereas | |
dictionary["bogus"] | |
# would raise a KeyError. | |
# If omitted, default_value is None, such that | |
dictionary.get("bogus") # <-- No default specified -- defaults to None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To exit a script you can use: | |
import sys | |
sys.exit() | |
# You can also provide an exit status value, usually an integer. | |
import sys | |
sys.exit(0) | |
# Exits with zero, which is generally interpreted as success. Non-zero codes are usually treated as errors. The default is to exit with zero. | |
import sys |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import zipfile | |
def zipdir(path, ziph): | |
# ziph is zipfile handle | |
for root, dirs, files in os.walk(path): | |
for file in files: | |
ziph.write(os.path.join(root, file)) |
NewerOlder