Skip to content

Instantly share code, notes, and snippets.

View ttscoff's full-sized avatar
💭
Breathing

Brett Terpstra ttscoff

💭
Breathing
View GitHub Profile
@ttscoff
ttscoff / app-alias-completion.sh
Created November 2, 2013 00:37
Command-specific Bash filename completions for application aliases
## Applications
# alias acorn="open -a Acorn"
# alias alpha="open -a ImageAlpha"
# alias tp="open -a TaskPaper"
# alias byword="open -a Byword"
# alias xc="open -a Xcode"
#
## subp is a custom function for finding Sublime projects
function _complete_app_alias()
@ttscoff
ttscoff / oft.sh
Created November 2, 2013 16:28
Open File Type script. Fuzzy matches extension fragment to open matching files.
oft() {
local target fnd app all
target="."
fnd=''
if [[ $# == 0 ]]; then
echo -n "Enter an ext or partial ext: "
read ext
else
[[ "$1" =~ -[h\?] ]] && echo "Usage: oft [-a \"app name\"] [path (fragments)] file extension (fragment)" && return
while [[ $# -gt 1 ]]; do
@ttscoff
ttscoff / wakeup.sh
Created November 12, 2013 21:30
Wake remote Mac on local network
#!/bin/bash
if [[ $1 =~ ((mb)?air|pibble) ]]; then
target="pibble.local"
else
target="macpro.local"
fi
ping -c 1 $target &> /dev/null
@ttscoff
ttscoff / chapters.css
Created December 2, 2013 15:39
Chapter numbers in CSS
body {
counter-reset: chapter; /* create a chapter counter scope */
}
h1:before {
content: "Chapter " counter(chapter) ". ";
counter-increment: chapter; /* add 1 to chapter */
}
h1 {
counter-reset: subchapter; /* set section to 0 */
}
anonymous
anonymous / gist:8075952
Created December 21, 2013 22:30
Tags files and directories per Brett Terpstra's approach.
#!/usr/bin/env ruby
def package?(file)
results = `mdls -name kMDItemContentTypeTree "#{file}" | grep com.apple.package`
results.length > 0
end
base = ARGV[0]
if !base
script = File.basename("#{__FILE__}")
@ttscoff
ttscoff / Marker.js
Created December 22, 2013 05:19
Bookmarklet for Markdownifying webpage selections
// Marker, a bookmarklet for Markdownifying webpage selections
// javascript:(function(){var p=document.createElement("p");p.innerHTML="<strong>Loading&hellip;</strong>";p.id="loadingp";p.style.padding="20px";p.style.background="#fff";p.style.left="20px";p.style.top=0;p.style.position="fixed";p.style.zIndex="9999999";p.style.opacity=".85";document.body.appendChild(p);document.body.appendChild(document.createElement("script")).src="https://gist.github.com/ttscoff/8078727/raw/Marker.js?x="+(Math.random());})();
(function () {
function callback() {
(function ($) {
var raw, userSelection;
if (window.getSelection) {
// W3C Ranges
userSelection = window.getSelection ();
// Get the range:
@ttscoff
ttscoff / getpinboard.rb
Created December 27, 2013 23:37
Pinboard to Mavericks tags
#!/usr/bin/ruby
##############################################################################
### getpinboard.rb by Brett Terpstra, 2011 <http://brettterpstra.com>
### Retrieves Pinboard.in bookmarks, saves as local .webloc files for
### Spotlight searching.
###
### Optionally adds OpenMeta tags and/or saves page as PDF (see config below)
### Use -r [NUMBER OF DAYS] to reset the "last_checked" timestamp (primarily
### for debugging).
###
@ttscoff
ttscoff / marked_index.rb
Last active February 20, 2025 09:46
Generate an index file for Marked from a file list using Marked's include syntax
#!/usr/bin/ruby
$output = ""
$max_depth = 3
parent_dir = false
if RUBY_VERSION.to_f > 1.9
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
end
@ttscoff
ttscoff / Open Together Note in Marked.applescript
Created January 20, 2014 02:38
Quick AppleScript for opening the selected [Together 3](http://reinventedsoftware.com/together/) note(s) in [Marked.app](http://marked2app.com)
tell application "Together 3"
set _sel to selected items
repeat with _note in _sel
set _file to original filename of _note
tell application "Marked" to open POSIX path of _file
end repeat
end tell
@ttscoff
ttscoff / image_tag.rb
Created February 16, 2014 15:02
Custom Jekyll image tag with lazy loading and CDN changes
# Title: Simple Image tag for Jekyll
# Authors: Brandon Mathis http://brandonmathis.com
# Felix Schäfer, Frederic Hemberger
# Description: Easily output images with optional class names, width, height, title and alt attributes
#
# Syntax {% img [class name(s)] [http[s]:/]/path/to/image [width [height]] [title text | "title text" ["alt text"]] %}
#
# Examples:
# {% img /images/ninja.png Ninja Attack! %}
# {% img left half http://site.com/images/ninja.png Ninja Attack! %}