Skip to content

Instantly share code, notes, and snippets.

@robjwells
robjwells / Restart in Windows.applescript
Last active October 10, 2015 11:17
Quickly restart your Mac into Windows
set deviceID to (do shell script "diskutil list | awk '/YourBootcampPartition/ {print $NF}'")
do shell script "bless -device /dev/" & deviceID & " -legacy -setBoot -nextonly" ¬
with administrator privileges
tell application "Finder" to restart
@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
@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 / Prefixr.applescript
Created April 5, 2013 09:22
Prefixr AppleScript with formatting
tell application "BBEdit"
-- Get selection and call the Prefixr API
set theSel to the contents of the selection of text 1 of text window 1
set prefixed to (do shell script "curl -sSd css=\"" & theSel & "\" http://prefixr.com/api/index.php")
-- Calculate current indent
set initialSpaces to ""
repeat
set spaceOffset to the offset of " " in theSel
if spaceOffset is not 1 then
@robjwells
robjwells / rjw-syntax-readme.md
Last active December 19, 2015 10:29
robjwells.com syntax highlighting

This is essentially Dr Drang’s script for syntax highlighting and adding line numbers to code snippets, which calls [highlight.js][hljs] to do the colouring.

My code is largely the same, but rewritten to not require JQuery and done so in the module pattern to keep functions out of the global namespace. (On [my site][rjw] this is my personal JavaScript file, so I’d also stick any other functions I write myself inside the module.)

@robjwells
robjwells / RJW Light.bbcolors
Created July 6, 2013 17:07
robjwells custom BBEdit colour scheme
<?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>BackgroundColor</key>
<string>rgba(0.968627,0.968627,0.968627,1.000000)</string>
<key>CommentsColor</key>
<string>rgba(0.466667,0.466667,0.466667,1.000000)</string>
<key>CommentsColor_Markdown</key>
<string>rgba(0.466667,0.466667,0.466667,1.000000)</string>
@robjwells
robjwells / days.py
Last active December 21, 2015 05:19
days - print the number of days between now and a given date
#!/usr/local/bin/python3
"""\
Days
Calculate the number of days between a date and today or another date
Usage:
days <date> [<second_date> --format=<fmt>]
Options:
-f <fmt>, --format=<fmt> A strptime format string
@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
@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 / 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)