Skip to content

Instantly share code, notes, and snippets.

@pudquick
pudquick / nibbler.py
Last active February 16, 2023 06:07
nibbler - Use .nib files with python to quickly make UIs
# OFFICIAL REPO: https://github.com/pudquick/nibbler
# (this gist will be preserved for historical purposes)
# demo video here:
# https://www.dropbox.com/s/k0bpekd13muknmz/nibbler%20-%20by%20frogor.mp4?dl=0
# Example script using nibbler:
# from nibbler import *
#

Principles of Adult Behavior

  1. Be patient. No matter what.
  2. Don’t badmouth: Assign responsibility, not blame. Say nothing of another you wouldn’t say to him.
  3. Never assume the motives of others are, to them, less noble than yours are to you.
  4. Expand your sense of the possible.
  5. Don’t trouble yourself with matters you truly cannot change.
  6. Expect no more of anyone than you can deliver yourself.
  7. Tolerate ambiguity.
  8. Laugh at yourself frequently.
@pudquick
pudquick / spotlight_exclusions.py
Last active April 27, 2022 16:47
List and control Spotlight exclusions in OS X via python and pyobjc on OS X 10.11
# Only tested on OSX 10.11.5
import objc
from Foundation import NSBundle
Metadata_bundle = NSBundle.bundleWithIdentifier_('com.apple.Metadata')
functions = [
('_MDCopyExclusionList', b'@'),
('_MDSetExclusion', b'@@I'),
]
@pudquick
pudquick / 8021x_inspect.py
Last active September 27, 2022 10:04
802.1x configuration / data collection on OS X using python and the PrivateFramework "EAP8021X.framework"
# This was all run from user space
# I haven't tested it with root
# ... but it didn't prompt for any permissions under userspace ^_^
# Tested on 10.11.5
import objc
from Foundation import NSBundle
EAP8021X_bundle = NSBundle.bundleWithPath_('/System/Library/PrivateFrameworks/EAP8021X.framework')
Security_bundle = NSBundle.bundleWithIdentifier_('com.apple.security')
import base64
import getpass
import sys
import xml.etree.ElementTree as Et
import urllib
import urllib2
reload(sys)
sys.setdefaultencoding('utf-8')
@bruienne
bruienne / create_osx_pbkdf2_plist.py
Created April 24, 2016 15:52
Create an MDM-compatible PBKDF2 hash and plist for use with AccountConfiguration
#!/usr/bin/python
# Requires passlib: pip install passlib
from passlib.hash import pbkdf2_sha512
from passlib.util import ab64_decode
from biplist import *
# Checksum size must be 128 bytes for use as OS X password hash!
pbkdf2_sha512.checksum_size = 128
hash = pbkdf2_sha512.encrypt("password", rounds=38000, salt_size=32)
@pudquick
pudquick / pid_runtime.py
Last active February 7, 2019 21:53
Number of seconds a process has been running on OS X in python
from ctypes import CDLL, util, c_int, c_uint, byref, sizeof
import time
# We just need a large enough buffer for the result
# On 64-bit systems, this struct is 648 bytes, so 1024 bytes is enough
BUFFER_SIZE = 1024
CTL_KERN = 1
KERN_PROC = 14
KERN_PROC_PID = 1
@pudquick
pudquick / loginwindow_events.py
Created April 7, 2016 08:15
Send polite Logout / "really" Logout / Restart / Shutdown Apple Events to loginwindow via python and pyObjC
import struct, objc
from Foundation import NSBundle
from Cocoa import NSAppleEventDescriptor
def OSType(s):
# Convert 4 character code into 4 byte integer
return struct.unpack('>I', s)[0]
# Create an opaque pointer type to mask the raw AEDesc pointers we'll throw around
AEDescRef = objc.createOpaquePointerType('AEDescRef', '^{AEDesc=I^^{OpaqueAEDataStorageType}}')
@bearfrieze
bearfrieze / comprehensions.md
Last active December 23, 2023 22:49
Comprehensions in Python the Jedi way

Comprehensions in Python the Jedi way

by Bjørn Friese

Beautiful is better than ugly. Explicit is better than implicit.

-- The Zen of Python

I frequently deal with collections of things in the programs I write. Collections of droids, jedis, planets, lightsabers, starfighters, etc. When programming in Python, these collections of things are usually represented as lists, sets and dictionaries. Oftentimes, what I want to do with collections is to transform them in various ways. Comprehensions is a powerful syntax for doing just that. I use them extensively, and it's one of the things that keep me coming back to Python. Let me show you a few examples of the incredible usefulness of comprehensions.

@timsutton
timsutton / record_screencap.py
Created March 16, 2016 18:48
Screen recording with Python and AVFoundation
#!/usr/bin/python
# pylint: disable-msg=e1101,e0611
import time
import AVFoundation as AVF
import Quartz
from Foundation import NSObject, NSURL
def main():