Skip to content

Instantly share code, notes, and snippets.

View amacal's full-sized avatar

Adrian Macal amacal

View GitHub Profile
from zipfile import ZipFile
with ZipFile('terraform_0.13.4_linux_amd64.zip') as archive:
# archive filename
assert archive.filename == 'terraform_0.13.4_linux_amd64.zip'
# its consistency
assert archive.testzip() == None
from zipfile import ZipFile, Path
with ZipFile('python-3.9.0-docs-pdf-a4.zip') as archive:
# all-at-once way
for info in archive.infolist():
assert info.filename.startswith('docs-pdf')
# or pathlike way
root = Path(archive)
assert root.is_dir()
from zipfile import ZipFile, Path
with ZipFile('python-3.9.0-docs-pdf-a4.zip') as archive:
# extract everything
archive.extractall()
# just one file
archive.extract('docs-pdf/faq.pdf', 'docs')
# pathlike way
provider "aws" {
region = var.region
}
terraform {
backend "s3" {}
}
variable "region" {}
variable "plan_name" {}
PLAN_NAME := booking-system
LOCKS_TABLE := terraform-locks
REGION_NAME := eu-west-1
BUCKET_NAME := terraform-state-$(shell aws sts get-caller-identity --query Account --output text)
init:
@terraform init \
-backend-config="region=$(REGION_NAME)" \
-backend-config="bucket=$(BUCKET_NAME)" \
provider "aws" {
region = var.region
}
variable "region" {}
variable "plan_name" {}
resource "aws_s3_bucket" "data_bucket" {
bucket = "${var.plan_name}-data"
acl = "private"
from zipfile import ZipFile, Path
with ZipFile('archive.zip', 'w') as archive:
# include single file
archive.write('terraform')
# nested file
archive.write('docs-pdf/faq.pdf')
# or inline content
create transient table ecds_db.playground.orders
(
-- meta
_etl_id bigint autoincrement start 1 increment 1,
_etl_id_prev bigint,
_etl_updated_at timestamp_ntz,
_etl_deleted_at timestamp_ntz,
-- key
id bigint,
-- attributes
select count(1)
from ecds_db.playground.orders
where and _etl_deleted_at is null
and _etl_id not in
(
select _etl_id_prev
from ecds_db.playground.orders
where _etl_id_prev is not null
)
create transient table ecds_db.playground.orders
(
id bigint,
id_prev bigint,
)