Skip to content

Instantly share code, notes, and snippets.

@timsutton
timsutton / handle_sp_error.diff
Created June 5, 2013 12:52
Small fix to possibly handle broken system_profiler by dying immediately, instead of only timing out.
diff --git a/code/client/munkilib/munkicommon.py b/usr/local/munki/munkilib/munkicommon.py
index 428bc14..999947d 100755
--- a/code/client/munkilib/munkicommon.py
+++ b/usr/local/munki/munkilib/munkicommon.py
@@ -2032,7 +2032,11 @@ def getSPApplicationData():
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
try:
- output, unused_error = proc.communicate(timeout=60)
+ output, err = proc.communicate(timeout=60)
@robmathers
robmathers / readinglisturls.py
Last active November 16, 2023 21:18
Prints out URLs of items in Safari’s Reading List
#!/usr/bin/env python
import plistlib
from shutil import copy
import subprocess
import os
from tempfile import gettempdir
import sys
import atexit
BOOKMARKS_PLIST = '~/Library/Safari/Bookmarks.plist'
#!/usr/bin/python
import urllib
from xml.etree import ElementTree as ET
from distutils.version import LooseVersion
data = urllib.urlopen('https://softwareupdate.vmware.com/cds/vmw-desktop/fusion.xml').read()
xml = ET.fromstring(data)
updates = []

Moved

Now located at https://github.com/JeffPaine/beautiful_idiomatic_python.

Why it was moved

Github gists don't support Pull Requests or any notifications, which made it impossible for me to maintain this (surprisingly popular) gist with fixes, respond to comments and so on. In the interest of maintaining the quality of this resource for others, I've moved it to a proper repo. Cheers!

@drdrang
drdrang / Cleanbar.py
Last active July 6, 2017 20:28
Clean up the statusbar of an iOS screenshot. The time in the statusbar is maintained, but all other graphics are stripped out and replaced with graphics that show full battery and signal strength. The cellular provider is replaced with the Apple logo, . All graphics are built into the script, which works for any Retina iOS device in any orienta…
#!/usr/bin/python
import Image
import base64, zlib
# Jay Parlar convinced me to turn this data structure
# from a dictionary into an object.
class PackedImage(object):
def __init__(self, mode, size, data):
self.mode = mode
@pudquick
pudquick / notify.py
Last active September 3, 2023 16:51
Notification in pyobjc
# Banner-style (default)
from Foundation import NSUserNotification, NSUserNotificationCenter
def notify(title, subtitle, text):
notification = NSUserNotification.alloc().init()
notification.setTitle_(str(title))
notification.setSubtitle_(str(subtitle))
notification.setInformativeText_(str(text))
notification.setSoundName_("NSUserNotificationDefaultSoundName")
NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>catalogs</key>
<array>
</array>
<key>conditional_items</key>
<array>
<dict>
@bruienne
bruienne / sign_configprofile.sh
Created October 23, 2014 21:11
Sign config profile from CLI
openssl smime -sign -nodetach -in "My Awesome.mobileconfig" -signer MyAwesomeCert.pem -inkey MyAwesome.key -outform DER -out "My Awesome Signed.mobileconfig" -certfile MyAwesomeCert.pem
@timsutton
timsutton / Notes.md
Last active August 29, 2015 14:08 — forked from arubdesu/Notes.txt
<p>
My programming language of preference is python for the simple reason that I feel I write better code faster with it then I do with other languages. However also has a lot of nice tricks and idioms to do things well. And partly as a reminder to myself to use them, and partly because I thought this might be of general interest I have put together this collection of some of my favourite idioms. I am also putting this on <a href="https://gist.github.com/codefisher/9d7993ddbf404c505128">gist.github.com</a> so that anyone that wants to contribute there own things can, and I will try and keep this post up to date.
</p>
<h2>enumerate</h2>
<p>
A fairly common thing to do is loop over a list while also keeping track of what index we are up to. Now we could use a <code>count</code> variable, but python gives us a nicer syntax for this with the <code>enumerate()</code> function.
<script src="https://gist.github.com/codefisher/9d7993ddbf404c505128.js?file=enumerate.py"></script>