Skip to content

Instantly share code, notes, and snippets.

import base64
from Crypto.Cipher import AES # pip install pycrypto or pycryptodome
from Crypto.Hash import SHA256
from Crypto import Random
__all__ = ['encrypt', 'decrypt']
def encrypt(key, text, **kwargs):
@justengel
justengel / emailer.py
Created December 6, 2019 15:09
Simple send_mail function to using environment variables.
import os
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
# Check older version compatibility
if not hasattr(smtplib, "SMTPNotSupportedError"):
smtplib.SMTPNotSupportedError = smtplib.SMTPDataError
@justengel
justengel / qimage_label.py
Created December 11, 2019 16:10
Qt re-sizable image label.
from qtpy import QtCore, QtWidgets, QtGui
class QImageLabel(QtWidgets.QLabel):
doubleClicked = QtCore.Signal()
def loadFile(self, filename):
"""Load the image with the given filename."""
pm = QtGui.QPixmap()
with open(filename, 'rb') as f:
import os
import win32com.client # Requires "pip install pywin32"
__all__ = ['get_xl_properties', 'get_file_details']
# https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.tools.excel.workbook.builtindocumentproperties?view=vsto-2017
BUILTIN_XLS_ATTRS = ['Title', 'Subject', 'Author', 'Keywords', 'Comments', 'Template', 'Last Author', 'Revision Number',
'Application Name', 'Last Print Date', 'Creation Date', 'Last Save Time', 'Total Editing Time',
@justengel
justengel / pdf_to_jpg.py
Last active June 4, 2020 19:30
Convert pdf file to jpeg.
"""
Convert PDF images to jpg files
Requirements:
* Install imagemagick http://www.imagemagick.org/download/binaries/
* Install ghostscript https://www.ghostscript.com/download.html
* pip install wand
"""
import os
from wand.image import Image
@justengel
justengel / merge_pdf.py
Created June 4, 2020 19:36
Merge multiple pdf files into one pdf file.
"""
Merge multiple pdf files into one pdf file.
Args:
f (list/str): List of filenames to merge
out (str): Save filename to merge all of the files into.
Requires:
* pip install PyPDF2
@justengel
justengel / office_to_html.py
Last active April 23, 2023 19:15
Convert Microsoft Office documents to html or pdf files that can be viewed in a web browser.
"""Convert office document to file formats that may be visible in a web browser. This file uses microsoft office to
convert the files, so Windows OS is assumed and required!
Requirements:
* pywin32>=228 # Not available for Python3.8 at this time
Server Requirements:
* uvicorn>=0.11.5
* fastapi>=0.58.0
* python-multipart>=0.0.5
@justengel
justengel / gcal_scheduler.py
Last active September 19, 2022 04:40
Quick google calendar utilities
"""
https://developers.google.com/calendar/v3/reference/events/insert
"""
import os
import pickle
import datetime
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
@justengel
justengel / mortgage_calculator.html
Last active June 23, 2020 21:10
Calculate mortgage payments.
<html>
<head>
<title>Mortgage Calculator</title>
</head>
<body>
<h1>Mortgage Calculator</h1>
<h2>References</h2>
<ul>
@justengel
justengel / upload_package.py
Created June 29, 2020 16:07
Change a library version and upload it to pypi.
"""
Change a library version and upload it to pypi.
If you are updating the version, this script assumes a __meta__.py file exists in the package you want to upload.
Warning:
This has not been tested on all platforms!
Requirements:
* shell_proc>=1.1.1