Skip to content

Instantly share code, notes, and snippets.

@mazieres
Last active November 27, 2019 05:04
Show Gist options
  • Save mazieres/8017a984b1e12fcb1e469b11a1dd59e3 to your computer and use it in GitHub Desktop.
Save mazieres/8017a984b1e12fcb1e469b11a1dd59e3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import subprocess
def cli(cmd_str):
process = subprocess.Popen(cmd_str, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
output, error = process.communicate()
output, error = [x if len(x) > 0 else None
for x in (output.decode().strip(), error.decode().strip())]
return output, error
import os
import shutil
def delete_whatever(path_to_whatever):
if not os.path.exists(path_to_whatever):
return False
elif os.path.isfile(path_to_whatever):
os.remove(path_to_whatever)
else:
shutil.rmtree(path_to_whatever, ignore_errors=False, onerror=None)
return True
def chunks(li, n):
if li == []:
return
yield li[:n]
yield from chunks(li[n:], n)
def flatten(li):
return [item for sublist in li for item in sublist]
from datetime import datetime
def get_now():
return datetime.now().__str__()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment