Skip to content

Instantly share code, notes, and snippets.

View angstwad's full-sized avatar

Paul Durivage angstwad

View GitHub Profile
@angstwad
angstwad / enumerate_async.py
Last active October 24, 2024 02:34
enumerate with asyncio in Python
# Copyright 2024 Paul Durivage <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@angstwad
angstwad / lazyfiletype.py
Last active May 1, 2024 21:05
Better argparse.FileType - lazily open files passed as arguments rather than them being opened immediately
# Copyright 2024 Paul Durivage <[email protected]>
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@angstwad
angstwad / chdir.py
Last active April 3, 2024 20:42
os.chdir, but a context manager
# Copyright 2024 Paul Durivage <[email protected]>
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@angstwad
angstwad / urls.txt
Created March 21, 2022 15:55
Apple TV 4K URLs
https://sylvan.apple.com/Aerials/2x/Videos/comp_CH_C007_C011_PSNK_v02_HDR_FINAL_20180709_HDR_4K_HEVC.mov
https://sylvan.apple.com/Aerials/2x/Videos/comp_CH_C002_C005_PSNK_v05_HDR_FINAL_20180709_HDR_4K_HEVC.mov
https://sylvan.apple.com/Aerials/2x/Videos/comp_CH_C007_C004_PSNK_v02_HDR_FINAL_20180709_HDR_4K_HEVC.mov
https://sylvan.apple.com/Aerials/2x/Videos/comp_C004_C003_PS_v01_HDR_PS_20180925_HDR_4K_HEVC.mov
https://sylvan.apple.com/Aerials/2x/Videos/comp_C003_C003_PS_v01_HDR_PS_20180925_HDR_4K_HEVC.mov
https://sylvan.apple.com/Aerials/2x/Videos/comp_C001_C005_PS_v01_HDR_PS_20180925_HDR_4K_HEVC.mov
https://sylvan.apple.com/Aerials/2x/Videos/DB_D008_C010_4K_HDR_HEVC.mov
https://sylvan.apple.com/Aerials/2x/Videos/comp_DB_D008_C010_PSNK_v21_HDR_PS_20180914_F0F16157_HDR_4K_HEVC.mov
https://sylvan.apple.com/Aerials/2x/Videos/DB_D001_C001_4K_HDR_HEVC.mov
https://sylvan.apple.com/Aerials/2x/Videos/comp_DB_D001_C001_PSNK_v06_HDR_PS_20180824_HDR_4K_HEVC.mov
@angstwad
angstwad / app.py
Last active June 2, 2021 23:11
todo flask app
# Import Flask, Jsonify and Requests
from flask import Flask, jsonify, request
# Create the web applicatiion via Flask
app = Flask(__name__)
# Existing To-Do List
# it's easiest to manipulate if this is a dict where key is the id and value is the todo
todos = {
1: "Buy Hitman 3",
@angstwad
angstwad / signals.py
Created October 14, 2020 18:00
A simple script to catch any valid OS signals and simulate an action in response to a signal
import argparse
import functools
import logging
import os
import signal
import sys
import time
_LOG_FORMAT = "%(levelname)s:%(asctime)s:%(name)s:%(message)s"
logging.basicConfig(stream=sys.stdout, format=_LOG_FORMAT)
@angstwad
angstwad / set_cover_10.txt
Created March 25, 2020 15:35
Snippets for Blog: Solving a Set Cover Problem in Cloud IAM on GCP
roles/axt.admin
roles/billing.admin
roles/billing.creator
roles/compute.xpnAdmin
roles/container.hostServiceAgentUser
roles/datacatalog.categoryFineGrainedReader
roles/datafusion.serviceAgent
roles/iam.serviceAccountTokenCreator
roles/iap.httpsResourceAccessor
roles/orgpolicy.policyAdmin
@angstwad
angstwad / set_cover_9.py
Created March 25, 2020 15:31
Snippets for Blog: Solving a Set Cover Problem in Cloud IAM on GCP
while remaining:
for perm in remaining:
# get set of roles which contain permission
satisfy = perms_to_roles[perm]
# sort roles by the number of permissions they contain, select role
# with the most
sorted_roles = sorted((role, perms_counts[role])
for role in satisfy)
selected = sorted_roles[-1][0]
@angstwad
angstwad / set_cover_8.py
Created March 25, 2020 15:30
Snippets for Blog: Solving a Set Cover Problem in Cloud IAM on GCP
remaining = unique_perms - roles_to_perms['roles/owner']
@angstwad
angstwad / set_cover_7.py
Created March 25, 2020 15:29
Snippets for Blog: Solving a Set Cover Problem in Cloud IAM on GCP
selected_roles = {role_with_most_perms,}