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 / 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 / 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 / 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:
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 / 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 */
}
@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 / 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 / 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 / ifttt-pocket_to_nvalt.rb
Created November 1, 2013 12:05
A Hazel script for converting IFTTT-saved Pocket favorites to nvALT notes
#!/usr/bin/env ruby
# Works with IFTTT recipe https://ifttt.com/recipes/125999
#
# Set Hazel to watch the folder you specify in the recipe.
# Make sure nvALT is set to store its notes as individual files.
# Edit the $target_folder variable below to point to your nvALT
# ntoes folder.
require 'date'
require 'open-uri'
require 'net/http'
@ttscoff
ttscoff / tagfiler.rb
Last active March 22, 2025 09:34
Moves files to folders based on special tags in OS X Mavericks
#!/usr/bin/env ruby
# encoding: utf-8
# tag primary folders =Tagname
# target them with #Tagname
# tag subfolders with @nickname
# target them with :nickname
# if no tagged folder exists but there's a matching folder name, that's used
# otherwise it will create folders based on :tags
# :tags can be strung together :bt:Drafts:testing for nesting
# Only one #Tag and one :path should exist in a file's tags