Skip to content

Instantly share code, notes, and snippets.

View GadgetSteve's full-sized avatar

Steve (Gadget) Barnes GadgetSteve

  • Bridgend, UK
View GitHub Profile
@GadgetSteve
GadgetSteve / send_big.py
Created October 28, 2024 19:29
Send big files to WORK_EMAIL split into chunks & optionally encrypted. Includes reassebly script as mail body.
#! python
# encoding=utf-8
"""
SendBig
Send bigger files than the email limit.
"""
import sys
import os
@GadgetSteve
GadgetSteve / check_windows_locked.py
Created October 22, 2024 04:20
Detect if windows is locked
# coding: utf-8
"""
check_windows_locked.py
Copyright: (c) Steve Barnes 2024
Author: Steve Barnes <[email protected]>
Check if a windows system is screen locked.
"""
import sys
@GadgetSteve
GadgetSteve / where_am_i.py
Last active June 27, 2022 06:42
Importable execution position in python
"""
Importable get called from file & location.
Based on a tweet by Ned Batchelder @nedbat
"""
import inspect
def where_am_i():
""" Return the current filename and line number. """
bf = inspect.currentframe().f_back
return (bf.f_globals.get("__file__", "interactive"), bf.f_lineno)
@GadgetSteve
GadgetSteve / lineno_demo.py
Last active June 26, 2022 08:28
How to get the line number in python
# coding: utf-8
# Originally from a tweet by Ned Batchelder @nedbat
import inspect
def __line__():
""" Return the current line number. """
return inspect.currentframe().f_back.f_lineno
if __name__ == "__main__":
print(f"At {__line__()} of {__file__}")
@GadgetSteve
GadgetSteve / cgi-post.py
Created October 30, 2021 09:42 — forked from SteveBarnes-BH/cgi-post.py
CGI Debugging - sometimes you have a web page that uses CGI and you need to see what data is being POSTed.
#!/usr/bin/env python
"""
This script is based on https://cgi.tutorial.codepoint.net/file-upload but with changes as needed.
To use:
- Download the web page to be debugged.
- Edit it to replace `action="/cgi-bin/cgi-post"` with `action="/cgi-bin/cgi-post.py"` (on Windows on Linux you can simply rename this file to not have .py at the end.
- place in a cgi-bin subdirectory of the one where you saved the web page
- start a simple web server with ` python -m http.server 8001 --bind localhost --cgi`
@GadgetSteve
GadgetSteve / list_licenses.py
Last active January 27, 2021 16:27 — forked from WLPhoenix/list_licenses.py
Python license lister
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import pkg_resources
def get_pkg_license(pkgname):
"""
Given a package reference (as from requirements.txt),
@GadgetSteve
GadgetSteve / py_preview.ps1
Created November 7, 2020 11:57
Tell explorer to preview python files as text
Set-ItemProperty Registry::HKEY_CLASSES_ROOT\.py -Name PerceivedType -Value text
Set-ItemProperty Registry::HKEY_CLASSES_ROOT\.pyw -Name PerceivedType -Value text
@GadgetSteve
GadgetSteve / demo.svg
Created March 1, 2020 15:29
Create image like Picture from: E. Lucon Oscillateurs coupl ́es, d ́esordre et
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@GadgetSteve
GadgetSteve / RIPy2prompt.py
Created December 29, 2018 08:44
Python 2 countdown prompt
#!/usr/bin/env python
# encoding utf-8
"""
If you set your PYTHONSTARTUP environment variable to point to this file
with an absolute path then it will change your python 2 prompt to countdown
to the End Of Life of Python 2.
Copyright Steve Barnes <[email protected]> 2017
License: Creative Commons
"""
@GadgetSteve
GadgetSteve / VerCheck.py
Created July 26, 2017 20:38
Reminder of LooseVersion
from distutils.version import LooseVersion
if LooseVersion(requests.__version__) <= LooseVersion('2.2.0'):
raise SystemExit("This program requires Python requests 2.2.0 or later.")