Skip to content

Instantly share code, notes, and snippets.

@dsaiztc
dsaiztc / scp-cheatsheet.md
Created November 8, 2018 17:56 — forked from dehamzah/scp-cheatsheet.md
SCP Cheatsheet

Basic Syntax

$ scp source_file_path destination_file_path

Uploading

Single file

import ipaddress
for host in ipaddress.ip_network('204.93.240.0/24').hosts():
print(host)
SELECT TRIM(pgn.nspname) AS SCHEMA,
TRIM(a.name) AS TABLE,
id AS TableId,
decode(pgc.reldiststyle,
0, 'EVEN',
1,det.distkey ,
8,'ALL'
) AS DistKey,
decode(pgc.reldiststyle,
8,NULL,
@dsaiztc
dsaiztc / pwd.py
Last active September 6, 2018 08:06
import string
import random
chars = string.ascii_letters + string.digits + string.punctuation
chars = string.ascii_letters + string.digits
pwd_length = 16
''.join((random.choice(chars)) for x in range(pwd_length))
cursor = None
rows = []
total_rows = -1
while(True):
try:
total_rows += 1
row = next(cursor)
rows.append(row)
except bson.errors.InvalidBSON:
logger.exception('Failed to parse document')
sudo python -m smtpd -n -c DebuggingServer localhost:25

Remove all stopped containers

docker rm $(docker ps -a -q)

Remove all untagged images

docker rmi $(docker images | grep "^<none>" | awk "{print $3}")
@dsaiztc
dsaiztc / .gitconfig
Last active March 19, 2018 15:21
~/.gitconfig
[credential]
helper = cache --timeout=3600
[status]
submoduleSummary = true
[alias]
work = log --pretty=format:\"%C(yellow)%h %ar (%ai) %C(auto)%d %Creset %s , %Cblue%cn\" --graph --all
/* https://stackoverflow.com/a/30783772/3149679 */
WHERE
created >= date_trunc('week', CURRENT_TIMESTAMP - interval '1 week')
AND
created < date_trunc('week', CURRENT_TIMESTAMP)
@dsaiztc
dsaiztc / exponential_backoff.py
Last active July 12, 2017 10:42
Exponential backoff.
from time import sleep
def try():
success = False
retries = 0
max_retries = N
while not success:
# Execute task, success = True if successful
if retries == max_retries: