12th August 2021
Coding⚑
Python⚑
Python Snippets⚑
-
New: Explain how to find a static file of a python module.
import pkg_resources file_path = pkg_resources.resource_filename("my_package", "assets/config.yaml"),
-
New: Explain how to delete a file.
import os os.remove('demofile.txt')
-
New: Explain how to measure elapsed time between lines of code.
import time start = time.time() print("hello") end = time.time() print(end - start)
pexpect⚑
-
New: Explain how to read the output of a command run by pexpect.
import sys import pexpect child = pexpect.spawn('ls') child.logfile = sys.stdout child.expect(pexpect.EOF)
DevOps⚑
Infrastructure as Code⚑
Terraform⚑
-
New: Explain how to ignore the change of an attribute.
resource "aws_instance" "example" { # ... lifecycle { ignore_changes = [ # Ignore changes to tags, e.g. because a management agent # updates these based on some ruleset managed elsewhere. tags, ] } }
-
New: Explain how to define the default value of an variable that contains an object as empty.
variable "database" { type = object({ size = number instance_type = string storage_type = string engine = string engine_version = string parameter_group_name = string multi_az = bool }) default = null
-
New: Explain how to do a conditional if a variable is not null.
hcl resource "aws_db_instance" "instance" { count = var.database == null ? 0 : 1 ...