Skip to content

Instantly share code, notes, and snippets.

View natan's full-sized avatar

Nathan Spindel natan

View GitHub Profile
@natan
natan / secretloginitems.rb
Created July 15, 2015 20:33
Display the Login Items for your account registered via launchd by ServiceManagement.framework (vs. System Preferences' own Login Items)
#!/usr/bin/env ruby
user_id = `id -u`.chomp
secret_login_items_path = "/var/db/com.apple.xpc.launchd/loginitems.#{user_id}.plist"
puts File.read(secret_login_items_path)
@natan
natan / gist:d13a1be46251d26519c2
Created November 27, 2014 23:37
iOS Voicemail Backup
#!/usr/bin/ruby
# Tested on an iOS 8 iPhone backup done via iTunes
# point this to the desired backup found in ~/Library/Application Support/MobileSync/Backup/
backup_path = "/Users/nathan/Desktop/PhoneBackup/"
voicemails_path = "/Users/nathan/Desktop/Voicemail/"
Dir.foreach(backup_path) do |item|
@natan
natan / gist:3032f0fd43fb79b729f6
Last active February 2, 2022 22:46
Simultaneous map and filter in Swift
extension Array {
// Similar to Lisp's map function that allows returning nil in the transform to omit the item from the resulting array.
func mapAndFilter<U>(transform: (T) -> U?) -> U[] {
var results = U[]()
for item in self {
if let transformedItem = transform(item) {
results.append(transformedItem)
}
}
return results
@natan
natan / archive-desktop.rb
Last active October 11, 2015 05:17
Move everything on your desktop into ~/Dropbox/Documents/Desktops/<yyyy-mm-dd>/
#!/usr/bin/env ruby
require 'FileUtils'
require 'date'
def create_dir_if_necessary(path)
Dir.mkdir(path) unless File.directory?(path)
end
desktops_path = File.expand_path("~/Dropbox/Documents/Desktops")