Skip to content

Instantly share code, notes, and snippets.

@Integralist
Integralist / Python Asyncio Timing Decorator.py
Last active June 30, 2024 09:27
Python Asyncio Timing Decorator
import asyncio
import time
def timeit(func):
async def process(func, *args, **params):
if asyncio.iscoroutinefunction(func):
print('this function is a coroutine: {}'.format(func.__name__))
return await func(*args, **params)
else:
@shapeshed
shapeshed / aws-cf-logs
Last active September 12, 2022 09:10
Fetch AWS Cloudfront Logs, decompress, combine into a single file and remove comments
#!/usr/bin/env bash
BUCKET=$1
CWD=$(pwd)
if [[ -n $1 ]]; then
aws s3 sync s3://$BUCKET/cf-logs .
cat *.gz > combined.log.gz
find $CWD ! -name 'combined.log.gz' -name '*.gz' -type f -exec rm -f {} +
gzip -d combined.log.gz
@russss
russss / deskew.py
Created September 10, 2018 12:05
Automatic scanned image rotation/deskew with OpenCV
import cv2
import numpy as np
def deskew(im, max_skew=10):
height, width = im.shape
# Create a grayscale image and denoise it
im_gs = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
im_gs = cv2.fastNlMeansDenoising(im_gs, h=3)
@mattwang44
mattwang44 / downloadFromS3_async.py
Last active June 5, 2024 13:43
async download from AWS S3 using aiobotocore
import os
import asyncio
import aiobotocore
import io
from PIL import Image
AWS_ACCESS_KEY_ID = os.environ['AWS_ACCESS_KEY_ID']
AWS_SECRET_ACCESS_KEY = os.environ['AWS_SECRET_ACCESS_KEY']
@carlwgeorge
carlwgeorge / yum-clean-all-demystified.md
Last active May 16, 2024 05:16
yum clean all demystified

TLDR:

  • yum clean all == clean most
  • rm -rf /car/cache/yum/* == really clean everything

From the man page:

Note that these commands only operate on files in currently enabled
repositories. If you use substitution variables (such as $releasever) in your cachedir configuration, the operation is further restricted to the current
values of those variables.

@mkczyk
mkczyk / .git-plugin-bash.sh
Last active June 14, 2024 06:26
Git aliases for bash (based on Oh My Zsh Git plugin)
#!/bin/bash
# To ~/.bashrc file add line:
# source ~/.git-plugin-bash.sh
# Based on Oh My Zsh Git plugin (without zsh functions):
# https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/git/git.plugin.zsh
# https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/git
#
@veuncent
veuncent / youtube_analytics_oauth.md
Last active May 16, 2024 19:28
Authentication for Google / YouTube Analytics using a Brand Account

Google / YouTube Authentication using a Brand Account

Below describes the only way I was able to get (programmatic) access to the YouTube Analytics API on behalf of our Brand Account. Google documentation is convoluted, to say the least, so if you know a more straightforward way, please do share.

Getting a Client ID and Refresh Token

  1. Create a Project in the Developers Console - https://console.developers.google.com/
  2. Go to the Library tab and enable desired APIs (e.g. YouTube Analytics)
  3. Go to OAuth consent screen and make project external. Select Test mode
@xiaopc
xiaopc / draw_table.py
Last active April 29, 2024 08:27
Draw a table using only Pillow
from PIL import Image, ImageFont, ImageDraw
from collections import namedtuple
def position_tuple(*args):
Position = namedtuple('Position', ['top', 'right', 'bottom', 'left'])
if len(args) == 0:
return Position(0, 0, 0, 0)
elif len(args) == 1:
return Position(args[0], args[0], args[0], args[0])
@FreddieOliveira
FreddieOliveira / docker.md
Last active July 17, 2024 01:42
This tutorial shows how to run docker natively on Android, without VMs and chroot.

Docker on Android 🐋📱

Edit 🎉

All packages, except for Tini have been added to termux-root. To install them, simply pkg install root-repo && pkg install docker. This will install the whole docker suite, left only Tini to be compiled manually.


Summary

@esc5221
esc5221 / delete_gha_runs_by_name.py
Created December 14, 2022 10:36
delete github actions workflow runs by name
# resolves : Is there a way to delete or hide old/renamed Workflows? #26256
# https://github.com/community/community/discussions/26256
from multiprocessing.dummy import Pool as ThreadPool
import requests
TOKEN = "{YOUR_GH_TOKEN}"
OWNER_REPO = "esc5221/example_repo"
DELETE_TARGET_RUN_NAME = "{RUN NAME}"