Welcome to the lab.

Bookmarklet: Clean highlighted code for copying

[Tweet : ADN : nvALT]

I made a little bookmarklet this morning for cleaning up highlighted code blocks in web pages for copying into my notes. You just click it on any web page and all pre>code blocks and table.highlight elements will be turned into plain text.

Once code blocks are cleaned, double-clicking anywhere in the block will select all the contents of the field.

If this would be of use to you, you can drag the bookmarklet below to your menu bar and try it out. It doesn’t currently work on GitHub in this form, but you can create a local bookmarklet from the source if needed. GitHub, of course, offers raw source easily, so it’s not really a concern.


It’s not heavily tested, so let me know if you see bugs. It also only handles the most common code highlighters, so there are more than likely code blocks it will fail on, but it serves my needs as is.

Side notes: By default it will add code fences (triple backticks), and try to detect the language. If a language is found in the pre or table element’s classes or data-language attribute (falling back to those of the parent div or code tag), it will be added to the opening fence. The source script allows these to be overridden with an options object passed to the main function (e.g. CC.cleaner({fence: false, detectLang: false}), but I don’t currently have that implemented in the bookmarklet version.

Web Excursions for November 30, 2015

[Tweet : ADN : nvALT]

This week’s web excursions brought to you by the The Black Friday Mac Bundle. 10 great Mac apps, including Memories, Call Recorder, Folding Text, Divvy, Timing, and more for $15.

Cyber Monday?

The Just Stay Home Marked 2 Sale
I’ve extended this for a few days, use code STAYHOMEANDWRITE to get $3 off the direct version of Marked 2.
The Productive Writer’s Bundle
Pick up Marked 2, Texts, WordCounter, and bonus goodies for $24.99. A complete set of apps and tools for getting writing done.
Timing.app 20% off
Timing is a great app for automatic time tracking on Mac, and one I use personally. It’s 20% off for the week, check it out.

The Rest

A Comprehensive Guide to the iTunes Affiliate Program
My friend John Voorhees, developer of Blink: Better Affiliate Links, wrote a huge guide to the iTunes affiliate program on MacStories. If you ever share iTunes links, check it out.
See tabs (chords only) for guitar and ukulele and piano. It plays along with any YouTube video and shows the chords, as well as a fret diagram.
Booking.js from Timekit.io
A free calendar and scheduling widget that works with Google Calendar and can be embedded in web pages. I’ve been looking for something this simple for a while.
A (work-in-progress) JavaScript-based HTML to Markdown converter developed for use in Quiver.
FeedEx.Net: The Feed Expander [beta]
Expand RSS feeds to full text versions.
Slides Framework: Beautiful Website Builder - Designmodo
Generate mobile-friendly single-page websites easily. A one-time purchase for 70 slides and 11 (combinable) quick-start templates. The slides include PSD, Sketch and HTML sources.

Check out The Black Friday Mac Bundle.

The “just stay home” Marked 2 sale

[Tweet : ADN : nvALT]

I wasn’t planning to do anything with Marked 2 for Black Friday this year. More than that, really, I was planning not to do anything. Then I went outside.

I ran a few errands. The co-op was deserted. The coffeehouses weren’t unusually packed. All of Winona’s historic downtown had a normal or sub-normal population. Then I went to the “Big Box” end of town for a single garage door opener battery. I may have PTSD (Post traumatic shopping disorder).

In light of these events, I’m offering you $3 to just stay home. Skip the consumerist orgy. Pour a glass of wine, put on some Bauhaus, Johnny Cash, Nick Cave, Lou Reed (or whatever the sad kids listen to these days), and just do some writing. Finish up that NaNoWriMo novel, do some blogging, catch up on project documentation, or just journal your Thanksgiving dinner as a potential therapy. Marked is good for all of that.

Here’s your coupon: STAYHOMEANDWRITE ($3 off the current $11.99 price of Marked 2). You can use it at checkout when purchasing the direct version. It’s good through Monday.

Don’t forget about the Productive Writer’s Bundle, either, which includes Marked, as well as Texts, WordCounter, and more at a fantastic price.

Blockbuster Kit: a pre-Black Friday deal for movie lovers

[Tweet : ADN : nvALT]

I’ve mentioned WALTR before, and am a happy user of Boom 2—a great utility for boosting and eq’ing all the sound that comes out of your Mac. Add Elmedia Player PRO and Beamer 3, and you have a great kit for high-quality movie viewing on your Mac (and sending to Apple TV or Chromecast).

All four apps are available in the Blockbuster Kit for $24.95 (a 73% discount), until Friday. The “Black Friday” price will be $30, so if you’re a movie lover, go grab it early!

Shell Tricks: Quick line numbering

[Tweet : ADN : nvALT]

It’s often useful to quickly see line numbers when viewing source code files. The less command and related tools can display with line numbers. There’s also the nl command, but it doesn’t number blank lines and tends to mess up formatting. There’s are ways that are more flexible and better looking. Enter grep and paste.

grep version

If you pass a “match everything” pattern to grep (.*) and include the -n flag, you’ll get the entire file passed back with line numbers followed by colons.

A quick alias makes this easily accessible:

alias grepno="grep --color=never -n -E '.*'"

Now you can just type grepno [filename.txt] to see numbered output.

$ grepno Rakefile
46:Rake.application.options.trace = false
48:run_time = Time.now

The nice thing about the -n switch is that you can actually search with it and see the resulting line numbers for just the matching lines. Same with ack, ag (Silver Searcher), and others.

I don’t love the output, though.

paste version

The paste command has a somewhat esoteric function:

The paste utility concatenates the corresponding lines of the given input files, replacing all but the last file’s newline characters with a single tab character, and writes the resulting lines to standard output.

For this tip, we’re overriding the newline-to-tab conversion (with the -d flag) and replacing newlines with TAB-newline, maintaining the newline but indenting it. sed = will number the lines in the output, and the -s switch on paste will restore our whitespace keeping the line number justified to the left.

# output a text file with line numbers
lno() {
    if [ $# == 0 ]; then
        echo "No filename provided."
        sed = "$1" | paste -s -d '\t\n' - -

This will give you nicely formatted, line-numbered output.

$ lno Rakefile
46  Rake.application.options.trace = false
47  verbose(false)
48  run_time = Time.now

You can pass it to less for (in my opinion) better-looking output than less’s default -n switch. You can also pipe it to grep to filter, generating the same paginated output as grep -n with better formatting. You can also redirect to a file (> output.txt) or the clipboard (| pbcopy) for line-numbered text you can share.

Web Excursions for November 23, 2015

[Tweet : ADN : nvALT]

slalert!: News Alerts in Slack
This new tool from Diffbot (I’m a fan of Diffbot for all kinds of web scraping) allows you to scour the web for mentions of your app or project and get alerts in Slack whenever it’s mentioned. Nifty.
Stock Up
Another great source for free stock photos, sourcing and searching 26 different free photo sites.
Rover – simple file browser for the terminal
A small, terminal-based (curses) utility for navigating file systems. vi-like keybindings, integration with environment variables, and file management capabilities.
Using Swift To Make Command Line Scripts - Part 1
A great rundown on using Swift to create CLIs with argument handling and full functionality.
A set of tools to assist in creating command line applications and tools. Colorize output and provide user interaction (ask, choose, agree).

Black Friday Deal at Udemy: 17,000+ online courses for $10 (48 hours only)

[Tweet : ADN : nvALT]

Black Friday $10 728x90

I’ve partnered with global online learning marketplace Udemy to bring you a Black Friday $10 deal on 17,000+ of their best selling courses.

Learning is no longer limited to a classroom or a book. We live in a world where we can learn new skills and concepts on-demand, at our own pace, and on an amazing array of devices. Udemy has both master and mini courses on everything from programming to photography, and I encourage you to take a look.

I think most of my readers will gravitate to the wide array of programming courses (covering everything from web development, JavaScript, and advanced libraries like Angular JS, to iOS, Android, Mac, and Windows programming), but who knows? You may find a new passion (like writing or yoga), master new business skills (like Excel), or maybe even a new career.

Starting today, you can get courses for $10, which is up to 98% off. The $10 deal only lasts 48 hours. After Thursday the price starts rising until Black Friday, when the sale ends at a price of $15 for courses. If you’re looking to learn, stock up early!

Smarter keyboard shortcuts for Finder

[Tweet : ADN : nvALT]

I frequently mention the capability of OS X to assign keyboard shortcuts to Services and other functions. At its most basic, though, the keyboard shortcut functionality can enhance and customize any application. As an example, Finder can be extended nicely for the keyboard-inclined.

Most features in Finder already have shortcuts, as you’ll see if you pull down any menu from the menu bar. There are a few that don’t, primarily contextual menu items, that can have shortcuts assigned to speed up your workflow.

To assign shortcuts, open System Preferences and navigate to the Keyboard pane. Once there, choose the Shortcuts tab and select App Shortcuts from the sidebar. Use the “+” button to add a new one. You can select “All Applications” for universal shortcuts, or a specific app (in this case Finder). Type the title of any menu item—exactly, including upper and lower case—and assign a shortcut. That’s it.

The most useful shortcuts I have assigned:

Show Package Contents
I use ⌃⌘P for this. When a bundle file (e.g. application or document bundle) is selected, pressing the combination will open it as a folder in Finder, the same as ⌘↓ does when a folder is selected.
Note that an ellipsis is not three periods, it’s a single character created by ⌥; (Option-Semicolon). With this one defined, pressing the key combo will pop up a dialog on any selected file(s) that I can use to tag quickly in Finder.
I had assumed for a long time that—because Finder changed the menu item title to “Compress [filename]” in the contextual menu—you couldn’t easily assign a shortcut to it. I mentioned on Mac Power Users that I’d used BetterTouchTool to solve the issue. While the BTT trick is very cool, it turns out (thanks @macfixer) that you can just use “Compress” as the menu item title and the shortcut will work.
Sorting and Display shortcuts
There are default shortcuts for sorting (Name, Modified date, etc.) and display grouping, but I’ve always found them obtuse. I assign these to standard Function keys, e.g. F1-F3 handle quickly sorting by Name, Date, or Size on my system.