Skip to content

Instantly share code, notes, and snippets.

@zooba
zooba / read_usn.c
Created May 24, 2022 22:25
Saving my read_usn method in case I want it later
// FILE_ID.Identifier is BYTE[16] containing a single 128-bit unsigned integer
static PyObject *
_PyLong_From_FILE_ID(FILE_ID_128 *id)
{
PyObject *low = PyLong_FromUnsignedLongLong(
*(unsigned long long*)&id->Identifier[0]
);
if (!low) {
return NULL;
}
@zooba
zooba / winrt-toast.py
Created September 8, 2020 08:47
Popping up a toast notification using the winrt library
from winrt.windows.ui.notifications import ToastNotificationManager, ToastNotification, ToastTemplateType
def toast(title, text):
xml = ToastNotificationManager.get_template_content(ToastTemplateType.TOAST_TEXT02)
ee = xml.get_elements_by_tag_name("text")
ee[0].append_child(xml.create_text_node(title))
ee[1].append_child(xml.create_text_node(text))
notifier = ToastNotificationManager.create_toast_notifier()
notifier.show(ToastNotification(xml))
@zooba
zooba / faderport-midi.py
Last active September 5, 2020 12:56
WinRT script showing MIDI in/out with the PreSonus Faderport
import asyncio
from winrt.windows.devices import midi
from winrt.windows.devices.enumeration import DeviceInformation
async def list_ports(kind=midi.MidiInPort):
devs = await DeviceInformation.find_all_async(kind.get_device_selector(), [])
return {d.name: d.id for d in devs}
async def main():
in_port_id = (await list_ports())['PreSonus FP2 [1]']
@zooba
zooba / pdf2png.txt
Last active September 6, 2020 11:59
Step by step converting a PDF page to PNG using WinRT
Python 3.7.8 (tags/v3.7.8:4b47a5b6ba, Jun 28 2020, 10:03:53) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, time
>>> PDF_FILENAME = input("Path to PDF: ")
>>> OUT_FILE = os.path.abspath(input("Path to output PNG: "))
>>>
>>> import winrt.windows.data.pdf as PDF
>>> from winrt.windows.storage import StorageFile
>>> op = StorageFile.get_file_from_path_async(PDF_FILENAME)
>>> time.sleep(0.5) # should really await, but this is easier
@zooba
zooba / prompt.ps1
Last active May 21, 2020 21:52
Powershell title updater
function Prompt {
$p = Get-Location
while ($p) {
if (Test-Path "$p\.git") { break }
if (Test-Path "$p\pyproject.toml") { break }
if (Test-Path "$p\setup.py") { break }
$p = Split-Path -Parent $p
}
if ($p) {
$n1 = Split-Path -Leaf $p
@zooba
zooba / git-sync.ps1
Created February 27, 2020 20:46
Git-Sync Powershell function
function Git-Sync {
git fetch --all --prune;
$alive = git for-each-ref refs/remotes --format '%(refname)';
$dead = git for-each-ref refs/heads --format '%(if)%(push)%(then)%(refname:short):%(push)%(end)' `
| ?{ ($_ -split ':')[1] -and -not (($_ -split ':')[1] -in $alive) } `
| %{ ($_ -split ':')[0] };
if ($dead) {
$current = git name-rev --name-only HEAD;
if ($current -in $dead) {
Write-Host "Branch '$current' about to be deleted."
@zooba
zooba / try-remove.py
Created March 11, 2019 01:50
Tool for seeing which Python stdlib modules have dependencies on others
import ast
import json
import sys
import sysconfig
from pathlib import Path
def remove(data, key):
removed = {key}
@zooba
zooba / decoded_line.py
Last active December 11, 2017 18:09
Sample Python code used in my North Bay Python 2017 session on PEP 551
# This code is the base-64 encoded payload from the single line above, with newlines added for readability.
__import__('gzip').decompress(
__import__('base64').b64decode(
__import__('urllib.request').request.urlopen('http://bit.ly/2iALS0l').read()
)
)
@zooba
zooba / pep551_payload.b64
Last active November 20, 2017 21:18
Base-64 encoded and gz compressed payload for my PEP 551 demo
H4sIAKxGE1oC/9WUwQqCQBCG74LvMNhBRZHOLsFKRgXlQhkhEQlhIMgW4vuT7lbqipZGh77TrM7nrPAzLtl7K+K4S29+8glZbWECB1mCHAX6opjfm6YhooYAKi9Rl4mxaGIMGIUMjDpN8V1hGogxwGzMtNCHpmoyXmY+nz8x35lPuGmjkl4mQkNNCFvMJqLJ7ttMgsop+h5lyMxR1cyz0Zo+Nqt+qJktua1ctH62fpL4fzGPsiRLtzSmmaY/C8Ut9wesA+ArxCcQkN0G1s50sfRminWOaBalWhJRzRUXzmF81HW98uXLNYUkphHEFBrdNv8D3lx05cIdYXfVEMQEAAA=
@zooba
zooba / pep551_payload.py
Last active November 20, 2017 20:49
Payload for my PEP 551 demo
INTERNET_GUY = [
" .,...:, ",
" :,:::::,. ",
" `,.';;;';, ",
" `,.;'''':. ",
" :'+'''; ",
" ;''';; ",
" ;''';;. ",
" ,,.:;;;:;:;;:':.::. ",
" .::,,;:;++''+:';,...` ",