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
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-18-04 |
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 +x | |
info() { | |
echo -e "\033[34m[INFO]\033[0m $1" | |
} | |
error() { | |
echo -e "\033[31m[ERROR] $1\033[0m" | |
} | |
success() { |
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
""" | |
Python - Abstract Class | |
Yes. Python has Abstract Base Class module allows to enforce that a derived class implements a particular method using a special @abstractmethod decorator on that method. | |
""" | |
from abc import ABCMeta, abstractmethod | |
class Animal: | |
__metaclass__ = ABCMeta | |
@abstractmethod |
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
# Build lists of matched lines - several flavors: | |
def lines_that_equal(line_to_match, fp): | |
return [line for line in fp if line == line_to_match] | |
def lines_that_contain(string, fp): | |
return [line for line in fp if string in line] | |
def lines_that_start_with(string, fp): | |
return [line for line in fp if line.startswith(string)] |
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
""" | |
=========================================== | |
['Error']['Code'] e.g. 'EntityAlreadyExists' or 'ValidationError' | |
['ResponseMetadata']['HTTPStatusCode'] e.g. 400 | |
['ResponseMetadata']['RequestId'] e.g. 'd2b06652-88d7-11e5-99d0-812348583a35' | |
['Error']['Message'] e.g. "An error occurred (EntityAlreadyExists) ..." | |
['Error']['Type'] e.g. 'Sender' | |
"""" | |
import boto3 | |
from botocore.exceptions import ClientError |
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 boto3 | |
client = boto3.client('s3', 'us-west-2') | |
transfer = boto3.s3.transfer.S3Transfer(client=client) | |
transfer.upload_file(file_name, bucket, key_name, extra_args={'ServerSideEncryption':'aws:kms', 'SSEKMSKeyId':'alias/aws/s3'}) | |
import boto3 | |
s3 = boto3.resource('s3') | |
s3.meta.client.upload_file(file_name, bucket, key_name, ExtraArgs={'ServerSideEncryption':'aws:kms','SSEKMSKeyId':'alias/aws/s3'}) |
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 json | |
import os | |
import requests | |
import boto3 | |
from datetime import datetime | |
from botocore.exceptions import ClientError | |
import io | |
import contextlib | |
import urllib3 |
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
def zipDir(dirPath, zipPath): | |
""" | |
Generate zip package with full path | |
""" | |
zipf = zipfile.ZipFile(zipPath , mode='w') | |
lenDirPath = len(dirPath) | |
for root, _ , files in os.walk(dirPath): | |
for file in files: | |
if re.search('setup.cfg', file): | |
logger.info('Skip file {}'.format(file)) |
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
from io import BytesIO | |
import gzip | |
import shutil | |
def upload_gzipped(bucket, key, fp, compressed_fp=None, content_type='text/plain'): | |
""" | |
Compress and upload the contents from fp to S3. If compressed_fp is None, the compression is performed in memory. | |
""" | |
if not compressed_fp: | |
compressed_fp = BytesIO() |
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
#urllib3 | |
import urllib.parse | |
test_string = 'refs/heads/feature/Hotfix-test-123-214' | |
print(urllib.parse.quote_plus(test_string)) |