Instantly share code, notes, and snippets.
lad1337 /logger_helper.py
CreatedJune 20, 2025 21:40
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
| importlogging | |
| importsys | |
| importstructlog | |
| fromstructlog.typesimportEventDict,Processor | |
| # https://github.com/hynek/structlog/issues/35#issuecomment-591321744 | |
| defrename_event_key(_,__,event_dict:EventDict)->EventDict: | |
| """ |
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
| @tool | |
| extendsEditorPlugin | |
| @export_file(".csv")varcsv_path="res://data/elements/elements.csv" | |
| @export_dirvartres_dir="res://resources/elements/" | |
| constconverter_path=preload("res://addons/elementimporter/ElementImporter.tscn") | |
| vardockedScene |
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
| #!/usr/bin/env python | |
| fromtimeimportsleep | |
| importrequests | |
| importpigpio | |
| API_KEY="put you octoprint api key here" | |
| GPIO=18 | |
| PI=pigpio.pi() |
lad1337 /globimport.py
CreatedMarch 23, 2018 08:43 — forked frommdomke/globimport.py
Python glob import 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
| importimportlib | |
| importpkgutil | |
| defglobimport(pattern): | |
| base,found,rest=pattern.partition('*') | |
| ifnot (foundorrest): | |
| try: | |
| importlib.import_module(base.rstrip('.')) | |
| exceptImportError: |
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
| defsliding_window(iterable,size,overlap=0): | |
| """ | |
| >>>list(sliding_window([1,2,3,4],size=2)) | |
| [(1,2), (3,4)] | |
| >>>list(sliding_window([1,2,3],size=2,overlap=1)) | |
| [(1,2), (2,3)] | |
| >>>list(sliding_window([1,2,3,4,5],size=3,overlap=1)) | |
| [(1,2,3), (3,4,5)] | |
| >>>list(sliding_window([1,2,3,4],size=3,overlap=1)) | |
| [(1,2,3), (3,4)] |
lad1337 /Copy as JIRA
Last activeFebruary 26, 2018 11:31
SequalPro: copy as Jira/MD table in python (very very naive) 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
| #!/usr/bin/env python | |
| # choose "Select Rows (TSV)" | |
| importsys | |
| importos | |
| table="" | |
| separator='||' | |
| forlineinsys.stdin.readlines(): | |
| table+="{sep}{c}{sep}\n".format(c=line.replace('\t',separator).strip(),sep=separator) | |
| separator='|' |
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
| #!/usr/bin/env python | |
| importsys | |
| # run this: pip install git+https://github.com/lad1337/python-plexapi@feature/download-progress | |
| USAGE="usage: python pcp.py <username> [<password>]" | |
| fromplexapi.mypleximportMyPlexAccount | |
| fromplexapi.videoimportEpisode | |
| fromplexapi.videoimportMovie | |
| fromplexapi.videoimportShow |
lad1337 /alembic-graph
Last activeDecember 17, 2025 07:09
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
| #!/usr/bin/env python | |
| importsys | |
| fromgraphvizimportDigraph | |
| dot=Digraph(comment='alembic') | |
| defsplit_line(line): | |
| bases,_,name_and_target=line.partition('->') | |
| id_and_stuff,_,desc=name_and_target.strip().partition(',') |
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
| importcec | |
| classPowerStatus(): | |
| def__init__(self,power_on): | |
| self.power_on=power_on | |
| def__str__(self): | |
| ifself.power_on: | |
| return'on' |
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
| fromCrypto.CipherimportAES | |
| importbase64 | |
| importre | |
| fromcodecsimportopen | |
| PADDING='{' | |
| BLOCK_SIZE=32 | |
| pad=lambdas:s+ (BLOCK_SIZE-len(s)%BLOCK_SIZE)*PADDING |
NewerOlder