Skip to content

Instantly share code, notes, and snippets.

@drdrang
drdrang / newproject
Created July 7, 2020 15:58
Script to create database entries, folders in iCloud, a folder in Mail, and a set of labels for a new project.
#!/usr/bin/python
import sqlite3
import os
import sys
from applescript import asrun
from subprocess import Popen, PIPE
import shutil
import requests
import json
@drdrang
drdrang / smarten.js
Created November 18, 2010 14:51
A very simple quote and dash smartener in JS. Used to make my tweets look nicer.
// Change straight quotes to curly and double hyphens to em-dashes.
function smarten(a) {
a = a.replace(/(^|[-\u2014/(\[{"\s])'/g, "$1\u2018"); // opening singles
a = a.replace(/'/g, "\u2019"); // closing singles & apostrophes
a = a.replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1\u201c"); // opening doubles
a = a.replace(/"/g, "\u201d"); // closing doubles
a = a.replace(/--/g, "\u2014"); // em-dashes
return a
};
@drdrang
drdrang / Purge Old Reminders.scpt
Last active July 6, 2021 13:19
AppleScript to delete all reminders more than 30 days old.
set remindersOpen to application "Reminders" is running
set monthAgo to (current date) - (30 * days)
tell application "Reminders"
set myLists to name of every list
repeat with thisList in myLists
tell list thisList
delete (every reminder whose completion date is less than monthAgo)
end tell
end repeat
@drdrang
drdrang / safari-feeds.py
Last active July 20, 2020 07:07
Extract feeds from Safari and print them as OPML.
#!/usr/bin/python
from plistlib import readPlist
from os import environ
from cgi import escape
# OPML template with header and footer.
opml = '''<?xml version="1.0"?>
<opml version="1.1">
<head>
@drdrang
drdrang / Location.py
Created January 9, 2014 04:55
A Pythonista script that gets the address, latitude, and longitude and sends them to Drafts.
import sys
import location, time
import urllib, webbrowser
# Handle argument, if present.
try:
a = sys.argv[1]
except IndexError:
a = ''
-- A function for escaping URLs and skeleton code for a test.
on URLescape(myURL)
set myURL to quoted form of myURL
set myURL to text from character 2 to -2 of myURL
set cmd to "
from urllib import quote
print quote(\"" & myURL & "\", \"/:\")
"
--return cmd
@drdrang
drdrang / Amazon referral link
Created October 17, 2014 18:50
A TextExpander AppleScript snippet for inserting an affiliate link to the current Amazon page.
@drdrang
drdrang / swicsfix.py
Created December 10, 2017 19:39
Clean up Southwest Airlines ICS files.
#!/usr/bin/python
from icalendar import Calendar
import sys
import copy
from datetime import timedelta
for ics in sys.argv[1:]:
# Open the ics file and extract the event and alarm.
cal = Calendar.from_ical(open(ics).read())
@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
@drdrang
drdrang / clockface
Last active August 4, 2016 21:13
Prints Emoji clockface of the given time rounded to the nearest half-hour. Uses current time if none given. After https://github.com/RobTrew/txtquery-tools/blob/master/utilities/emotime.sh
#!/usr/bin/python
# -*- coding: utf-8 -*-
from sys import argv
from time import strftime
clocks = {'12:00': '🕛', '12:30': '🕧', '1:00': '🕐', '1:30': '🕜',
'2:00': '🕑', '2:30': '🕝', '3:00': '🕒', '3:30': '🕞',
'4:00': '🕓', '4:30': '🕟', '5:00': '🕔', '5:30': '🕠',
'6:00': '🕕', '6:30': '🕡', '7:00': '🕖', '7:30': '🕢',