Skip to content

Instantly share code, notes, and snippets.

View keybase.md

Keybase proof

I hereby claim:

  • I am grahamgilbert on github.
  • I am grahamgilbert (https://keybase.io/grahamgilbert) on keybase.
  • I have a public key ASDdB4_Tt3Pfh7-qvEoOSZCAfoUJoxgTtv8YoyA3MTGHdwo

To claim this, I am signing this object:

View gist:0ddb239a004fb2c2bbcda4a60d2b4d43
select username,uuid,uid,gid,description,directory, case WHEN uuid in (SELECT users.uuid FROM user_groups INNER JOIN users ON user_groups.uid = users.uid WHERE user_groups.gid = 80) THEN "admin" ELSE "standard" END AS user_type from users;
@grahamgilbert
grahamgilbert / profileenforcer.py
Created November 2, 2018 20:57
Profile enforcer. This is an example, no warranty expressed or implied. Use at your own risk.
View profileenforcer.py
import sal.plugin
import requests
from django.conf import settings
SETTINGS = settings.PROFILE_SETTINGS
class Profileenforcer(sal.plugin.Widget):
description = 'Enforces profiles via MDM'
@grahamgilbert
grahamgilbert / clean_old_apple_updates.py
Created May 9, 2018 16:35
Clean out old apple updates (older than 24 hours) because softwareupdate often refuses to install them
View clean_old_apple_updates.py
#!/usr/bin/python
"""
Removes cached apple updates that are older than 24 hours
"""
import datetime
import os
import shutil
import sys
@grahamgilbert
grahamgilbert / History|-102230fa|entries.json
Last active February 2, 2023 00:10
Visual Studio Code Settings Sync Gist
View History|-102230fa|entries.json
{"version":1,"resource":"file:///Users/graham_gilbert/src/airbnb/puppet_control/data/switches/clienteng_machine/true.yaml","entries":[{"id":"89eh.yaml","timestamp":1659483293043},{"id":"kPHS.yaml","timestamp":1659483318396},{"id":"8ImG.yaml","timestamp":1659483330074},{"id":"bNr8.yaml","timestamp":1659545453065},{"id":"g15W.yaml","timestamp":1659545470189},{"id":"tKWY.yaml","timestamp":1659545787163},{"id":"t6Zf.yaml","timestamp":1659548976020},{"id":"YAip.yaml","timestamp":1663619107592},{"id":"ja80.yaml","timestamp":1663619118357},{"id":"k7ko.yaml","timestamp":1663799772944},{"id":"ac0j.yaml","timestamp":1663800381467},{"id":"VDrH.yaml","timestamp":1663876163366}]}
@grahamgilbert
grahamgilbert / API.md
Created June 24, 2017 15:44
Proposed changes to the API docs
View API.md

Sal has a REST API. You will need to create an API key before using it. You should send your private key and public key as headers (publickey and privatekey). Some actions can only be performed by API keys that have been marked as read / write in Sal.

General notes

Sal's API will generally return a response similar to the following:

{"count":362,"next":"https://sal.example.com/api/conditions/?condition=machine_type&page=2","previous":null,"results":[...]}
@grahamgilbert
grahamgilbert / base64_plist.py
Created September 5, 2016 11:03
Writing a base64 encoded string into a plist
View base64_plist.py
#!/usr/bin/python
import base64
import plistlib
import errno
import os
def mkdir_p(path):
try:
os.makedirs(path)
@grahamgilbert
grahamgilbert / autotimezone.sh
Created August 3, 2016 06:23
Enable Auto TimeZone
View autotimezone.sh
#!/bin/bash
/bin/launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist
uuid=`/usr/sbin/system_profiler SPHardwareDataType | grep "Hardware UUID" | cut -c22-57`
/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.$uuid LocationServicesEnabled -int 1
/usr/sbin/chown -R _locationd:_locationd /var/db/locationd
/bin/launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist
/usr/sbin/systemsetup -setusingnetworktime on
View RepairPermissions-1.0.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>RestartAction</key>
<string>RequireRestart</string>
<key>_metadata</key>
<dict>
<key>created_by</key>
<string>grahamgilbert</string>
@grahamgilbert
grahamgilbert / frontapp.py
Created January 5, 2016 14:38
Script that will check if an app has been inactive for five minutes and quits if needed
View frontapp.py
#!/usr/bin/python
""" Graham Gilbert 5/1/16
Change TARGET_APP and the app name on line 53 to your chosen app to quit.
Run this as often as you'd like via a launchagent.
No warranty expressed or implied. If things go kaboom, it's your problem!
"""
from AppKit import NSWorkspace