Skip to content

Instantly share code, notes, and snippets.

@robjwells
robjwells / NSAppleScript+RunHandler.h
Created July 5, 2015 14:46
NSAppleScript category to make calling AppleScript handlers (functions) easier
//
// NSAppleScript+RunHandler.h
// astest
//
// Created by Rob Wells on 30/01/2014.
// Copyright (c) 2014 Rob Wells. All rights reserved.
//
#ifndef kASAppleScriptSuite
#define kASAppleScriptSuite 'ascr'
@robjwells
robjwells / CopyCleaner.applescript
Last active April 28, 2021 03:00
BBEdit & TextWrangler text clean-up script for the Morning Star newspaper
-- By Rob Wells for the Morning Star
on open theStories
repeat with aStory in theStories
tell application "TextWrangler"
open aStory
tell the front text document
set encoding to "Unicode (UTF-8)"
educate quotes with replacing target
@robjwells
robjwells / Open in Chrome.applescript
Last active March 24, 2020 02:32 — forked from prenagha/Open In Chrome.scpt
Open current Safari URL in Chrome
-- Open current Safari URL in Chrome
--
-- Forked from https://gist.github.com/3153606
-- which was forked in turn from https://gist.github.com/3151932
tell application "System Events"
-- Check if Chrome is running
set chromeRunning to ((name of processes) contains "Google Chrome")
end tell
set -euf -o pipefail
cd $HOME/Desktop/
rm -r 'imac-setup' || true
mkdir -p 'imac-setup'
cd 'imac-setup'
xcode-select --install || true
curl -s --show-error https://bootstrap.pypa.io/get-pip.py | sudo /usr/bin/python
@robjwells
robjwells / phone_format.py
Last active December 5, 2016 14:26
Format UK phone number with area code
#!/usr/local/bin/python3
import re
import sys
area_codes = [
'020', '023', '024', '028', '029', '0113',
'0114', '0115', '0116', '0117', '0118', '0121',
'0131', '0141', '0151', '0161', '0191', '01200',
'01202', '01204', '01205', '01206', '01207', '01208',
@robjwells
robjwells / dayshift.py
Last active January 2, 2016 22:29
dayshift: get the date of the next or previous occurrence of a weekday
#!/usr/local/bin/python3
"""
Print the date of the next or last specified weekday.
Usage:
dayshift next <weekday> [--format=<fmt> --inline]
dayshift last <weekday> [--format=<fmt> --inline]
Options:
--format=<fmt>, -f <fmt> A strftime format string
@robjwells
robjwells / 24_to_12.py
Last active December 29, 2015 17:29
Convert 24-hour time to formatted 12-hour time
#!/usr/local/bin/python3
import sys
import re
input_text = sys.stdin.read()
regex_24 = re.compile(r'''\b
([01][0-9]|2[0-3]) # Hour (00-23)
([0-5][0-9]) # Mins (00-59)
\b''', flags=re.VERBOSE)
@robjwells
robjwells / copy_diff.py
Created October 17, 2013 08:29
copy_diff - Compare two sections of the same file See http://robjwells.com/post/61132555301/solo-diff
#!/usr/bin/env python3
import os
import re
import subprocess
os.chdir('/tmp')
with open(os.environ['BB_DOC_PATH']) as full_file:
sub_copy, orig_copy = re.split(r'#{2,} original copy #{2,}',
full_file.read(), flags=re.I)
@robjwells
robjwells / Underline.py
Last active December 24, 2015 07:18
Underline - BBEdit text filter
#!/usr/bin/env python3
import sys
bb_doc_arr = sys.stdin.readlines()
first_line = bb_doc_arr[0].rstrip('\n')
underline = '\n' + '=' * len(first_line) + '\n'
bb_doc_arr[0] = first_line + underline
print(''.join(bb_doc_arr), end='')
@robjwells
robjwells / scat.sh
Last active December 23, 2015 00:09
Super cat: cat files to the terminal with filename headers and line numbering
#!/bin/bash
if [ $# -eq 0 ]; then
echo 'usage: scat FILE [...]'
fi
for arg in "$@"; do
echo "===> $arg:"
cat -n "$arg"
echo