Skip to content

Instantly share code, notes, and snippets.

View non7top's full-sized avatar

non7top non7top

  • Pattaya
  • 23:59 (UTC +07:00)
View GitHub Profile
@non7top
non7top / aws-sagemaker-delete-apps.sh
Last active November 22, 2024 07:31 — forked from ojacques/aws-sagemaker-delete-apps.sh
List and delete all Amazon SageMaker KernelGateway apps which are still running
aws sagemaker list-apps --query "Apps[?Status=='InService']" | jq -r '.[] | "\(.AppName) \(.DomainId) \(.UserProfileName) \(.AppType)"' | \
while read AppName DomainId UserProfileName AppType; do \
echo Deleting $AppName for user $UserProfileName ... && \
aws sagemaker delete-app --domain-id $DomainId --app-type $AppType --app-name $AppName --user-profile $UserProfileName; done
@non7top
non7top / README.md
Created March 21, 2024 18:04 — forked from nymous/README.md
Logging setup for FastAPI, Uvicorn and Structlog (with Datadog integration)

Logging setup for FastAPI

This logging setup configures Structlog to output pretty logs in development, and JSON log lines in production.

Then, you can use Structlog loggers or standard logging loggers, and they both will be processed by the Structlog pipeline (see the hello() endpoint for reference). That way any log generated by your dependencies will also be processed and enriched, even if they know nothing about Structlog!

Requests are assigned a correlation ID with the asgi-correlation-id middleware (either captured from incoming request or generated on the fly). All logs are linked to the correlation ID, and to the Datadog trace/span if instrumented. This data "global to the request" is stored in context vars, and automatically added to all logs produced during the request thanks to Structlog. You can add to these "global local variables" at any point in an endpoint with `structlog.contextvars.bind_contextvars(custom

@non7top
non7top / argparse_dict_argument.py
Created December 29, 2023 22:04 — forked from vadimkantorov/argparse_dict_argument.py
A one-line example enabling Python's argparse to accept dictionary arguments
# Example:
# $ python argparse_dict_argument.py --env a=b --env aa=bb
# Namespace(env={'a': 'b', 'aa': 'bb'})
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--env', action = type('', (argparse.Action, ), dict(__call__ = lambda a, p, n, v, o: getattr(n, a.dest).update(dict([v.split('=')])))), default = {}) # anonymously subclassing argparse.Action
print(parser.parse_args())
@non7top
non7top / git-branch-cleaner
Created May 10, 2023 18:07 — forked from jdhoek/git-branch-cleaner
Bash script for cleaning up old git branches from local and remote repositories
#!/bin/bash
ME=$(basename $0)
function showHelp {
cat << EOF
Clean-up old git branches
Usage: $ME local show-last [AGE_IN_WEEKS]
$ME remote show-last REMOTE [AGE_IN_WEEKS]
@non7top
non7top / upload.php
Created April 13, 2022 11:32 — forked from taterbase/upload.php
Simple file upload in php
<!DOCTYPE html>
<html>
<head>
<title>Upload your files</title>
</head>
<body>
<form enctype="multipart/form-data" action="upload.php" method="POST">
<p>Upload your file</p>
<input type="file" name="uploaded_file"></input><br />
<input type="submit" value="Upload"></input>
@non7top
non7top / remove_crw.cmd
Created February 6, 2020 00:41 — forked from xvitaly/remove_crw.cmd
Remove telemetry updates for Windows 7 and 8.1
@echo off
echo Uninstalling KB3075249 (telemetry for Win7/8.1)
start /w wusa.exe /uninstall /kb:3075249 /quiet /norestart
echo Uninstalling KB3080149 (telemetry for Win7/8.1)
start /w wusa.exe /uninstall /kb:3080149 /quiet /norestart
echo Uninstalling KB3021917 (telemetry for Win7)
start /w wusa.exe /uninstall /kb:3021917 /quiet /norestart
echo Uninstalling KB3022345 (telemetry)
start /w wusa.exe /uninstall /kb:3022345 /quiet /norestart
echo Uninstalling KB3068708 (telemetry)
@non7top
non7top / remove-win10-spyware.bat
Created February 6, 2020 00:41 — forked from zorchenhimer/remove-win10-spyware.bat
Remove all the nasty stuff that was backported to Windows 7 and 8 from Windows 10.
@echo off
AT > NUL
if %ERRORLEVEL% EQU 1 (
echo Error: Not running as administrator.
echo Please right click the batch file and select 'Run as Administrator'
exit /b 1
)
echo Uninstalling bad updates...
@non7top
non7top / print_to_pdf.bas
Created September 5, 2019 20:14
LibreOffice Calc macros to print selected pages into pdf
sub print_to_pdf2
if len(ThisComponent.getURL())=0 then
msgbox "Save document first!"
exit sub
end if
If (Not GlobalScope.BasicLibraries.isLibraryLoaded("Tools")) Then
GlobalScope.BasicLibraries.LoadLibrary("Tools")
End If
@non7top
non7top / dump_http_headers.sh
Created June 15, 2019 15:08
dump_http_headers
# https://serverfault.com/a/633452
stdbuf -oL -eL /usr/sbin/tcpdump -A -s 10240 -i lo "tcp port 82 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)" | egrep -a --line-buffered ".+(GET |HTTP\/|POST )|^[A-Za-z0-9-]+: " | perl -nle 'BEGIN{$|=1} { s/.*?(GET |HTTP\/[0-9.]* |POST )/\n$1/g; print }'
@non7top
non7top / sni-sniff.py
Last active March 17, 2019 05:12
Allows to dump the hostname header from sni handshake
import os
import BaseHTTPServer, SimpleHTTPServer
import ssl, socket
CERTIFICATE_PATH = os.getcwd() + '/server.crt'
KEY_PATH = os.getcwd() + '/server.key'
def verify_tls(socket, hostname, context, as_callback=True):
print "SNI hostname: ", hostname