Skip to content

Instantly share code, notes, and snippets.

@ClarkGoble
ClarkGoble / SwiftArrayString
Last active August 29, 2015 14:02
Python string and array slicing in Swift
import Foundation
extension Array {
func get (range: Range<Int>) -> Array<T> {
var subarray = Array<T>()
for var i = range.startIndex; i < range.endIndex; i++ {
subarray += [self[i]]
}
@ClarkGoble
ClarkGoble / gist:6169144
Last active December 20, 2015 17:29
Python script for displaying a range of calendar events from the Calendar app in a nice formatted form
#!/usr/bin/env python
# -*- coding: utf-8 -*-
## comingevents.py
###################################################
# Lists in a nice format forthcoming events
from appscript import *
import osax
@ClarkGoble
ClarkGoble / opennyt.py
Created March 21, 2013 20:03
Open Safari front window NYT article with the paywall removed.
#!/usr/bin/env python
## opennyt.py
##
## Given a NYT article on the front page this reopens it without the paywall
import sys, os
import time, string, re
import urllib, json
#!/bin/bash
# get rid of duplicate apps by reindexing
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -seed -r -domain local -domain system -domain user
# reindex mail
rm $HOME"/Library/Mail/v2/MailData/Envelope Index"
rm $HOME"/Library/Mail/v2/MailData/Envelope Index-shm"
rm $HOME"/Library/Mail/v2/MailData/Envelope Index-wal"
@ClarkGoble
ClarkGoble / Get Front Finder Window Path
Created January 29, 2013 19:23
Gets path to front Finder window. I use this with Keyboard Maestro to type the path whenever I type ]fwin anywhere.
tell application "Finder" to get quoted form of POSIX path of (target of front Finder window as text)
@ClarkGoble
ClarkGoble / Get Finder Selection Paths
Last active December 11, 2015 21:59
Returns the paths of the selected Finder items quoted with a space between them. I use this with Keyboard Maestro to type the paths into the Terminal when I type ]finder there.
tell application "Finder" to set theSel to selection as alias list
set pathList to {}
repeat with anItem in theSel
set the end of pathList to quoted form of (POSIX path of (anItem as alias))
end repeat
set savedDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set myoutput to pathList as string
set AppleScript's text item delimiters to savedDelimiters
return myoutput
@ClarkGoble
ClarkGoble / Get Finder Selection Paths
Last active December 11, 2015 21:59
Puts on the clipboard the paths of all selected files in the Finder.
tell application "Finder" to set theSel to selection as alias list
set pathList to {}
repeat with anItem in theSel
set the end of pathList to quoted form of (POSIX path of (anItem as alias))
end repeat
set savedDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set the clipboard to pathList as string
set AppleScript's text item delimiters to savedDelimiters