Skip to content

Instantly share code, notes, and snippets.

View hansen-m's full-sized avatar

Matt Hansen hansen-m

View GitHub Profile
//
// Copyright (c) 2016, 2018 Nikolai Ruhe. All rights reserved.
//
import Foundation
public extension FileManager {
/// Calculate the allocated size of a directory and all its contents on the volume.
@pudquick
pudquick / passwords.py
Last active May 28, 2020 16:14
Generating passwords using SecurityFoundation's password assistant hidden functions on macOS via python & pyobjc
# Hat tip to https://github.com/anders/pwgen for various initial documentation
# For an alternative method, check out:
# https://gist.github.com/pudquick/8d3dedc337161b187a8a1c9564c83463
import objc
from Foundation import NSBundle, NSMutableArray, NSString
SecurityFoundation = NSBundle.bundleWithPath_('/System/Library/Frameworks/SecurityFoundation.framework')
success = SecurityFoundation.load()
@pudquick
pudquick / nvram.py
Created November 3, 2016 16:29
Get nvram values via python and pyobjc on macOS
import objc
from Foundation import NSBundle
IOKit_bundle = NSBundle.bundleWithIdentifier_('com.apple.framework.IOKit')
functions = [
("IORegistryEntryFromPath", b"II*"),
("IORegistryEntryCreateCFProperty", b"@I@@I"),
]
//
// NVRAMManager.swift
//
// Created by Matt Hansen on 1/30/16.
// The Pennsylvania State University.
//
// http://www.opensource.apple.com/source/system_cmds/system_cmds-643.30.1/nvram.tproj/nvram.c
import IOKit
import Foundation
@troyjr
troyjr / parseldap.R
Created July 5, 2014 00:21
R LDAP - parse ldap output from RCurl to dataframe ala Apache Directory studio export to csv.
library(RCurl)
library(gtools)
parseldap<-function(url, userpwd=NULL)
{
ldapraw<-getURL(url, userpwd=userpwd)
# seperate by two new lines
ldapraw<-gsub("(DN: .*?)\n", "\\1\n\n", ldapraw)
ldapsplit<-strsplit(ldapraw, "\n\n")
ldapsplit<-unlist(ldapsplit)
@chilcote
chilcote / gist:10010307
Created April 6, 2014 19:14
Fun with CoreWLAN and python
#!/usr/bin/env python
'''
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
'''
import objc
@gregneagle
gregneagle / com.foo.displaymirroring.plist
Last active December 18, 2015 03:59
A Python/PyObjC port of Fabian Canas's command-line mirror tool from http://mirror-displays.googlecode.com/. Demonstrates use of the Quartz Display Services to control display mirroring, and also shows how PyObjC handles "pass-by-reference" parameters. The LaunchAgent plist defines a job that runs at the loginwindow, running mirrortool.py to ena…
<?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>Disabled</key>
<false/>
<key>Label</key>
<string>com.foo.displaymirroring</string>
<key>LimitLoadToSessionType</key>
<array>