Skip to content

Instantly share code, notes, and snippets.

@gruber
gruber / Nadsat.markdown
Last active May 31, 2017 01:53
Nadsat: A Test of Gist

Nadsat: A JSON Extension for Droogs

You could peet it with vellocet or synthemesc or drencrom or one or two other veshches.

"_foo": {
	"about": "https://gist.github.com/json-feed-nadsat-extension",
	"horrorshow": true,
	"droog": "Alex"
}
@gruber
gruber / fix-antialiasing.js
Created December 4, 2012 02:45
Fix Antialiasing
// javascript:var%20style%20=%20%27*%20{-webkit-font-smoothing:%20auto%20!important}%27;var%20link_element%20=%20document.createElement(%27link%27);link_element.rel%20=%20%27stylesheet%27;link_element.href%20=%20%27data:text/css,%27%20+%20escape(style);document.getElementsByTagName(%22head%22)[0].appendChild(link_element);
var style = '* {-webkit-font-smoothing: auto !important}';
var link_element = document.createElement('link');
link_element.rel = 'stylesheet';
link_element.href = 'data:text/css,' + escape(style);
document.getElementsByTagName("head")[0].appendChild(link_element);
@gruber
gruber / gist:1063605
Created July 4, 2011 16:48
Simple Inbox Archiving Script for Apple Mail
-- See article here: http://daringfireball.net/2007/07/simple_inbox_sweeper
-- The following should be one long line:
set _description to "All unflagged, read messages in each IMAP account
inbox will be moved to the “Archive” mailbox corresponding to that
account. This action is not undoable."
tell application "Mail"
display alert "Archive read messages from IMAP inboxes?" buttons ¬
{"Cancel", "Archive"} cancel button 1 message _description
@gruber
gruber / Google Search
Created April 14, 2011 23:09
Perl script that can be used to create a system-wide service to do a Google web search. Input is the selected text in whatever the current app is. The result is a new Google query using your default web browser. (Mac OS X's built-in Search Google service
@gruber
gruber / Reply.scpt
Last active October 22, 2020 19:48
Prompt with options to "Reply" or "Reply All" when replying to a message with multiple recipients in Apple Mail for Mac OS X. Also does away with top-posting.
tell application "Mail"
set _sel to get selection
if (count of _sel) > 1 then
-- multiple message selection, usually a conversation thread
choose from list {"Reply", "Reply All"} with prompt "Unknown recipient count." default items {"Reply"}
try
set _menu_command to item 1 of the result
on error
return
@gruber
gruber / inline2ref.rb
Created September 9, 2011 21:25 — forked from ttscoff/inline2ref.rb
Convert inline Markdown links to references
#!/usr/bin/env ruby
def e_sh(str)
str.to_s.gsub(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/n, '\\').gsub(/\n/, "'\n'").sub(/^$/, "''")
end
def find_headers(lines)
in_headers = false
lines.each_with_index {|line, i|
if line =~ /^\S[^\:]+\:( .*?)?$/
@gruber
gruber / Battery Test — Safari.scpt
Last active January 18, 2021 17:35
A simple test to load a series of web pages in Safari repeatedly until the battery runs out.
on run
set imessage_id to "" -- leave blank to skip sending periodic iMessage progress updates, put your iMessage ID here to get updates as the script runs
set delay_seconds to 5 -- Don't set to 0, it runs too fast. 0.75 is a good setting for "go fast".
set computer_name to do shell script "scutil --get ComputerName"
set os_version to do shell script "sw_vers -productVersion"
set os_build to do shell script "sw_vers -buildVersion"
set _uptime to do shell script "uptime"
set url_list to {"http://techmeme.com", "http://www.consumerreports.org/laptops/macbook-pros-fail-to-earn-consumer-reports-recommendation/", "https://twitter.com/panzer/status/812367550734401536", "http://www.politico.com/story/2016/12/foreign-travelers-social-media-232930", "http://www.macworld.com/article/3153384/gaming/nintendo-plans-to-release-2-or-3-mobile-games-a-year-after-super-mario-runs-success.html", "http://www.wsj.com/articles/cyber-experts-cite-link-between-dnc-hacks-and-aggression-against-uk
@gruber
gruber / Paste URL From Safari Tab.scpt
Created June 29, 2015 00:01
Paste URL From Safari Tabs
set _old_delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {""}
tell application "System Events"
set _current_app to name of the first process whose frontmost is true
end tell
tell application "Safari"
set _urls to {}
repeat with i from 1 to 6 -- how many Safari windows to show URLs from
@gruber
gruber / Rename Active Document.scpt
Created August 8, 2012 03:51
Rename Active BBEdit Document
tell application "BBEdit"
activate
set old_name to name of text window 1
set dialog_result to display dialog "" default answer (old_name) ¬
buttons {"Cancel", "Rename"} default button 2 ¬
with icon note ¬
with title "Rename Active Document"
if button returned of dialog_result = "Rename" then
set new_name to text returned of dialog_result
set d to active document of text window 1
@gruber
gruber / tot.sh
Last active July 1, 2022 13:58 — forked from chockenberry/tot.sh
A shell script for Tot
#!/bin/bash
# Fork of CHOCK's original tot.sh to add support for dot "0" to target
# the first empty dot.
# https://gist.github.com/chockenberry/d33ef5b6e6da4a3e4aa9b07b093d3c23
#
# 2 Mar 2020
# + Incorporated suggestions from ShellCheck (https://www.shellcheck.net).
# Thanks to Ramsey Dow.
# + Changed call to `python` to `/usr/bin/python` to get Python 2, avoiding