Skip to content

Instantly share code, notes, and snippets.

@pudquick
pudquick / lines.py
Last active August 29, 2015 14:09
Uncommon variations on multi-line strings in python
# Variations on a theme.
# This first example uses a poorly documented trick in python regarding strings:
#
# https://docs.python.org/2/tutorial/introduction.html
# "Two or more string literals (i.e. the ones enclosed between quotes) next to each other
# are automatically concatenated."
#
# Then it's combined with the python implied line continuation by wrapping it in an outer
# set of parentheses.
@pudquick
pudquick / menu-tasking-enabler-10.hqx
Created November 19, 2014 02:14
As retrieved from gopher://sdf.org/1/computers/apple/mac/ui/
Date: Tue, 27 Dec 1994 04:52:52 -0500 (EST)
From: "Chris Thomas, ICONtact Developer Database Librarian" <THUNDERONE@delphi.com>
Subject: MenuTasking Enabler 1.0
Menutasking Enabler 1.0
(C) 1994 Chris K. Thomas. All Rights Reserved.
Reach me at <thunderone@delphi.com>
So you're taking a spin around your Mac with an Amiga-using friend of
yours, doing a download in the background and some other stuff in the
@pudquick
pudquick / 00 - Converting older Python.framework Xcode projects for Xcode 6.md
Last active August 6, 2022 16:07
An example of converting an older python.Framework Xcode project to compile in Xcode 6

When Apple moved to Xcode 5 (and later 6), they changed how you embed the Python.framework in a project: https://developer.apple.com/library/mac/technotes/tn2328/_index.html

This is a basic walkthrough of the process of conversion per that documentation for Xcode 6.

The example used here is the latest version of grahamgilbert's Crypt (at the time of this writeup): https://github.com/grahamgilbert/Crypt/tree/bdd49c849ed07fbc86d8c6f5bc31a525061d5077

(If you're viewing this via a gist blogging platform like roughdraft.io, make sure to view the original gist as there are image files included within the steps)

@pudquick
pudquick / beamsync.py
Last active September 28, 2023 15:16
#!/usr/bin/python
import ctypes, ctypes.util
# Import CoreGraphics as a C library, so we can call some private functions
c_CoreGraphics = ctypes.CDLL(ctypes.util.find_library('CoreGraphics'))
def disable_beam_sync(doDisable):
if doDisable:
# Disabling beam sync:
# 1st: Enable Quartz debug
@pudquick
pudquick / pip-mini.py
Last active October 23, 2016 03:44
Minimal version of pip in a standalone form for handling pure python situations (Pythonista, etc.)
# Standalone mini version of pip
# Geared towards Pythonista, but easily adaptable to other pure python installs
import argparse, copy, gzip, os, os.path, re, requests, shutil, site, sys, tarfile, time, xmlrpclib
# Where packages will end up installed
site_packages = site.USER_SITE
# Root of Pythonista saveable document location
pythonista_base = os.path.split(site_packages)[0]
# Temporary directory for work
@pudquick
pudquick / 00-prison_json.py
Last active August 29, 2015 14:16
Python script for parsing the current (as of this gist) Prison Architect file format
# You need python 2.7 for this
# FYI: There's a filepath hardcoded in this example at the end
# If you've got python installed, you can run this with: python prison_json.py
import re, mmap, collections, json, os
# These are special keys which should be treated as an array/list of values
multi_keys = ["Traits", "Reputation", "ReputationHigh"]
def dequote(keyname):
@pudquick
pudquick / xcrun.py
Created March 3, 2015 21:04
XCode path mangling in python
import struct, hashlib
def hashStringForPath(cls, path):
hash_path = [None] * 28;
md5_digest_hex = hashlib.md5(path).digest();
first_value = struct.unpack('>Q', md5_digest_hex[:8])[0];
second_value = struct.unpack('>Q', md5_digest_hex[8:])[0];
counter = 13;
while counter >= 0:
#!/usr/bin/env python
# To look at: https://github.com/kcrawford/mac-network/blob/master/lib/mac-network/wifi.rb
# To look at: https://stackoverflow.com/questions/28096630/mac-os-x-10-10-reorder-preferred-networks
'''
Playing around with CoreWLAN to return information about the wi-fi connection
Documentation:
https://developer.apple.com/library/mac/documentation/CoreWLAN/Reference/CWInterface_reference/translated_content/CWInterface.html
@pudquick
pudquick / reorder_wifi.py
Last active July 16, 2022 01:03
This python code uses Objective-C calls to reorder pre-existing SSIDs in your WiFi interfaces to place a preferred SSID at the top (without removing / re-adding)
#!/usr/bin/python
# As written, this requires the following:
# - OS X 10.6+ (may not work in 10.10, haven't tested)
# - python 2.6 or 2.7 (for collections.namedtuple usage, should be fine as default python in 10.6 is 2.6)
# - pyObjC (as such, recommended to be used with native OS X python install)
# Only tested and confirmed to work against 10.9.5
# Run with root