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 stream_unzip import stream_unzip | |
| data = ( | |
| b'PK\x03\x04\n\x00\x00\x00\x00\x00|\x99A[\x82\x89\xd1\xf7\x05\x00\x00\x00\x05\x00\x00\x00\x08' | |
| b'\x00\x1c\x00file.txtUT\t\x00\x03\xecn\xddh\xeen\xddhux\x0b\x00\x01\x04\xf6\x01\x00\x00\x04' | |
| b'\x14\x00\x00\x00HelloPK\x01\x02\x1e\x03\n\x00\x00\x00\x00\x00|\x99A[\x82\x89\xd1\xf7\x05\x00' | |
| b'\x00\x00\x05\x00\x00\x00\x08\x00\x18\x00\x00\x00\x00\x00\x01\x00\x00\x00\xa4\x81\x00\x00\x00' | |
| b'\x00file.txtUT\x05\x00\x03\xecn\xddhux\x0b\x00\x01\x04\xf6\x01\x00\x00\x04\x14\x00\x00\x00PK' | |
| b'\x05\x06\x00\x00\x00\x00\x01\x00\x01\x00N\x00\x00\x00G\x00\x00\x00\x00\x00' | |
| ) |
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
| # Deletes objects in bulk using boto3's delete_objects, but using multiple threads to achieve some | |
| # parallelism - in spite of the GIL multiple HTTP requests to S3 should happen at the same time. | |
| # Instead of looping over all keys under the root prefix, it walks the tree of keys of delimiter- | |
| # defined "folders" in a depth-first way, which allows each page to be processed by a separate | |
| # thread as its discovered. Depth-first is done because the depth is limited by the maximum key | |
| # size of 1024 in S3, and so means that there is a limit to the memory used by the algorithm to | |
| # store the next requests to make. This would not be the case with breadth-first because there is | |
| # no limit to how many keys are in any folder. | |
| # | |
| # To do the search in parallel, each bit of work (i.e. an HTTP request to fetch a page of keys |
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 pprint import pprint | |
| import boto3 | |
| repository_name = 'REPLACE_ME' | |
| client = boto3.client('ecr', region_name='eu-west-2') | |
| image_details = ( | |
| image_detail | |
| for page in client.get_paginator('describe_images').paginate( |
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 base64 | |
| import json | |
| import boto3 | |
| from cryptography.hazmat.primitives.ciphers.aead import AESGCM | |
| s3 = boto3.resource('s3') | |
| bucket = s3.Bucket('my-bucket') | |
| kms_client = boto3.client('kms') |
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
| { | |
| init: function(elevators, floors) { | |
| const intSort = function(a, b) { | |
| if (a < b) return -1; | |
| if (a > b) return 1; | |
| return 0; | |
| } | |
| const floorWantsUp = function(floorNum) { |
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
| # Restores all objects under a prefix in an S3 bucket to the version they were before being deleted. | |
| # Works by deleting the latest delete marker for the objects. | |
| import boto3 | |
| bucket = 'the-bucket' | |
| prefix = 'the-prefix/' | |
| region = 'eu-west-2' | |
| client = boto3.client('s3', region_name=region) | |
| paginator = client.get_paginator('list_object_versions') |
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
| # docker run --rm -it -p 5432:5432 -e POSTGRES_PASSWORD=password postgres:14 | |
| import pprint | |
| import threading | |
| import time | |
| from concurrent.futures import ThreadPoolExecutor | |
| from contextlib import contextmanager | |
| import psycopg2 | |
| import psycopg2.extras |
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 https://stackoverflow.com/a/68876046/1319998, which is itself inspired by https://stackoverflow.com/a/68814418/1319998 | |
| from contextlib import contextmanager | |
| from collections import namedtuple | |
| from ctypes import cdll, byref, string_at, c_char_p, c_int, c_double, c_int64, c_void_p | |
| from ctypes.util import find_library | |
| from sys import platform | |
| def query(db_file, sql, params=()): |
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 | |
| from urllib.parse import urlparse, parse_qsl | |
| import requests | |
| from rich import box | |
| from rich.console import Console | |
| from rich.table import Table | |
| with open(f'{os.environ["HOME"]}/.cf/config.json') as f: |
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 datetime | |
| import hashlib | |
| import hmac | |
| import urllib.parse | |
| def aws_sig_v4_headers(access_key_id, secret_access_key, pre_auth_headers, | |
| service, region, host, method, path, query, payload): | |
| algorithm = 'AWS4-HMAC-SHA256' |
NewerOlder