Welcome to the lab.

Exercise and ADHD

[Tweet : ADN : nvALT]

I’ve been exercising a lot lately. As my issues with getting the meds I need have started to seem hopeless, I began using long walks to clear my mind. It helped. I lost 10 pounds and started being able to get about 60 solid minutes of work clocked per day, which is a huge step up from a few months of being able to handle about 30 minutes (elapsed) and not enough time to actually complete anything.

I started with hiking. First a mile at a time, then two, then extending beyond the point where at least one of my dogs could keep up1. The farther I walked, the more work I could do afterward. I have the good fortune of living within walking distance of an amazing trail system in the bluffs of Southeast Minnesota. I can walk out my door and be at a trailhead in 2 minutes. I’ve gotten to know about 8 miles of single track quite well, and have plenty more to explore.

Then I was talking to my friend Luc Beaudoin (creator of MySleepButton, one of the most effective sleep aids I’ve found), and he mentioned that the key is “vigorous” exercise. So I started incorporating short sprints into my hikes. Part of what I love about hiking is observing the forests and plains around me, and trail running absolutely requires keeping your eyes on the trail in front of you (or else ankle sprain), so I only ran for the “boring” sections of trails. A few minutes of sprinting combined with 30-60 minutes of walking was still enough to break me into a full sweat and maintain a high pulse rate, and it turned out he was right. Just walking isn’t enough to help with things like ADHD.

Then I started doing Yoga. I have a good friend who teaches a class at a local wellness center, so I decided to try it. It was good for me. I felt great afterward, and the class setting worked well for keeping me going. I decided to try out some other classes, and went to a Forrest Yoga class. It was an hour and fifteen minutes of soaking my yoga mat with sweat.

After the first Forrest class, I went to a friend’s poetry reading. I was sitting there when all of the sudden my brain started working. Thoughts, ideas, and plans all started flowing the way they used to. It lasted a couple of hours. I’ve been able to replicate it since then, but it takes about an hour of exercise to get two hours of work, so it’s not a perfect solution. I have, however, lost almost 20 pounds now and am feeling better physically than I have since I was 25 (which was 12 years ago).

Yoga wasn’t easy for me to get started with. I don’t like games I can’t win, and doing a flexibility-and-core-strength workout as a fat, out-of-shape guy was awkward. My instructors were very helpful and supportive, and my classmates were all—if not 100% encouraging—absolutely not judgmental. Having pretty girls around you is great encouragement to focus and try not to look like an idiot, and having better-looking guys around brings out some kind of primal competition in me that makes me push myself further than I would just working out on my own. It’s going well.

I’ve completed the ADHD testing that was asked of me by the psychologist I’ve parted ways with, and it confirms an ADHD Inattentive Type diagnosis (again). I don’t know yet if that will translate to me getting back on the meds I need, but it’s a good start, and these months of desperation have led to some lifestyle changes that I absolutely needed. It will all work out in the end. It always does…

  1. Our German Shepherd can actually do 4+ miles fine with pep in his step, unless he gets SQUIRREL… and ends up running twice as far. Our middle-aged pit bull with synthetic knees, though, can only go about two miles before I have to carry her home.

Shell Tricks: shorten every line of output

[Tweet : ADN : nvALT]

Updated: Dr. Drang pointed out that the original functions were mostly working but flawed. I’ve updated this whole post.

This is a simple bash function that will take each line of the input piped to it and truncate it at a given length (default 70 characters), optionally inserting an ellipsis or other string if the line is truncated.

Here’s the basic trick, using sed with an example line length of 60:

short () {
	cat | sed -E "s/(.{60}).*$/\1/"
}

Here’s a more complete version of the function. It accepts a -l switch to truncate from the left instead of the right (default), and a -s STRING flag to allow the user to specify an ellipsis or other string to add to lines that have been truncated.

# Truncate each line of the input to X characters
# flag -s STRING (optional): add STRING when truncated
# switch -l (optional): truncate from left instead of right
# param 1: (optional, default 70) length to truncate to
shorten () {
	local helpstring="Truncate each line of the input to X characters\n\t-l              Shorten from left side\n\t-s STRING         replace truncated characters with STRING\n\n\t$ ls | shorten -s ... 15"
	local ellip="" left=false
	OPTIND=1
	while getopts "hls:" opt; do
		case $opt in
			l) left=true ;;
			s) ellip=$OPTARG ;;
			h) echo -e $helpstring; return;;
			*) return 1;;
		esac
	done
	shift $((OPTIND-1))

	if $left; then
		cat | sed -E "s/.*(.{${1-70}})$/${ellip}\1/"
	else
		cat | sed -E "s/(.{${1-70}}).*$/\1${ellip}/"
	fi
}

These functions can be added to any file that’s sourced during login, such as ~/.bash_profile. Then they can be used like:

cat filename.txt | shorten 20

You can shorten the output of any command:

ls -1 | shorten 15

Example output without shorten:

$ ls -1 2016-04*
2016-04-06-recap-march-and-everything-else.md
2016-04-12-arq-5-gets-a-big-speed-boost.md
2016-04-12-the-textexpander-subscription-snafu.md
2016-04-13-web-excursions-for-april-13-2016.md
2016-04-14-pdfpenpro-complete-pdf-power.md
2016-04-15-friday-freebie-infographic-icon-set.md
2016-04-19-udemy-courses-for-30-percent-off.md
2016-04-20-web-excursions-for-april-20-2016.md
2016-04-21-houdahspot-find-everything-fast.md

And with shorten to 10 characters, with ellipses:

$ ls -1 2016-04* | shorten -s ... 10
2016-04-06...
2016-04-12...
2016-04-12...
2016-04-13...
2016-04-14...
2016-04-15...
2016-04-19...
2016-04-20...
2016-04-21...

Shell Tricks: list files with most text matches

[Tweet : ADN : nvALT]

Here’s a Bash function for searching all text files in the current directory for a pattern, then listing the files containing matches in ascending order by number of matches. It’s mostly a proof of concept, but a useful companion to a basic grep search.

The meat of the script happens in an array declaration. It first uses grep -lIi -E "$patt" * 2> /dev/null to list files containing the provided pattern (case insensitive), ignoring binary files. The error redirect at the end of the command will ignore the errors thrown by directories. The results of this are fed to another grep command: grep -Hi -c -E "$patt" which outputs the match count for each file. The results are saved to the array.

After including the function in a sourced file (e.g. ~/.bash_profile), running matches -h will show the available flags and switches:

$ matches -h
Find files in the current directory containing the most occurrences 
of a pattern
	-c Include occurrence counts in output
	-r Reverse sort order (default ascending)
	-m COUNT Minimum number of matches required
	-h Display this help screen

 Example:
	# search for files containing at least 3 occurrences
	# of the word "jekyll", display filenames with counts

	$ matches -c -m 3 jekyll

Here’s the function for pasting into ~/.bash_profile (or other sourced file):

# Find files in the current directory containing the most occurrences of a pattern
# switch -c: turn on display of occurrence counts
# switch -r: reverse sort order (default ascending)
# flag -m COUNT: minimum number of occurrences required to include file in results
# param 1: (required) search pattern (regex allowed, case insensitive)
#
# Results are output in ascending order by occurrence count
matches () {

	local counts=false minmatches=1 patt width=1 reverse=""
	local helpstring="Find files in the current directory containing the most occurrences of a pattern\n\t-c         Include occurrence counts in output\n\t-r         Reverse sort order (default ascending)\n\t-m COUNT   Minimum number of matches required\n\t-h         Display this help screen\n\n	Example:\n\t# search for files containing at least 3 occurrences\n\t# of the word \"jekyll\", display filenames with counts\n\n\t$ matches -c -m 3 jekyll"

	OPTIND=1
	while getopts "crm:h" opt; do
		case $opt in
			c) counts=true ;;
			r) reverse="r" ;;
			m) minmatches=$OPTARG ;;
			h) echo -e $helpstring; return;;
			*) return 1;;
		esac
	done
	shift $((OPTIND-1))

	if [ $# -ne 1 ]; then
		echo -e $helpstring
		return 1
	fi

	patt=$1; shift

	OLDIFS=$IFS
	IFS=$'\n'

	declare -a matches=$(while read -r line; do \
	                grep -Hi -c -E "$patt" "$line"; \
	              done < <(grep -lIi -E "$patt" * 2> /dev/null) \
	              | sort -t: -${reverse}n -k 2)
	width=$(echo -n ${matches[0]##*:}|wc -c|tr -d ' ')

	for mtch in ${matches[@]}; do
		if [ ${mtch##*:} -ge $minmatches ]; then
			if $counts; then
				printf "%${width}d: %s\n" ${mtch##*:} "${mtch%:*}"
			else
				echo "${mtch%:*}"
			fi
		fi
	done

	IFS=$OLDIFS
}

Web Excursions for April 20, 2016

[Tweet : ADN : nvALT]

HoudahGeo 5 — Photo Geocoding & Geotagging for Mac
HoudahGeo 5 is out, adding a bunch of powerful features to the OS X photo geotagging app. New features include Places (saved coordinates and location names), drag-and-drop geocoding, Google Earth/Maps/KML export, direct camera import, and map searching.
Writing Workflow 2016, Part 2: Citations, Preview, and Export using Zotero, Marked 2, and Pandoc
A great rundown of a workflow for anyone who wants to incorporate citations and more advanced Pandoc features into Marked 2.
Franz
A free messaging app that combines chat and messaging services into one application. Slack, WhatsApp, WeChat, HipChat, Facebook Messenger, Telegram, Google Hangouts, GroupMe, Skype and more.
DeckHub
A Tweetdeck-style desktop client for GitHub. 15-day trial, $9.99 to purchase.
AppLandr - Beautiful landing pages for your mobile apps
Generate good-looking landing pages for mobile apps simply by providing the app’s store URL.

Udemy courses for 30% off

[Tweet : ADN : nvALT]

Udemy is offering a 30% discount on all of their courses for the duration of April. You can use the code TERPSTRA at checkout to apply the discount.

If you want to learn new skills and concepts on-demand, at your own pace and on an amazing array of devices, Udemy has both master and mini courses on everything from programming to photography. Take a look!

Just take a look at the available courses, and use the coupon code TERPSTRA at checkout.

Friday Freebie: Infographic Icon Set

[Tweet : ADN : nvALT]

For your Friday design pleasure, here’s a free set of infographic icons from 1001. The graphics include avatars, business charts and icons, mobile devices and more.

The download includes the following formats:

  • AI
  • EPS
  • PNGs (1024 x 1024 transparent png image of each icon)
  • SVG (individual SVG file for each icon)

Download the Infographic Icon Set.

The pack is licensed under a Creative Commons Attribution 3.0 Unported License.

Visit 1001freedownloads.com for more!

Web Excursions for April 13, 2016

[Tweet : ADN : nvALT]

Instaparser
Paid access to Instapaper’s web scraper. I’d like to incorporate this into Marky, but the cost wouldn’t even out. Still, one of the best tools available for finding the actual content in a web page.
Command - Chrome Extension
An open-source extension for Chrome that adds slash-commands (e.g. /giphy or /selfie) to text fields in your browser. If you’re a Slack or IRC user, you’re familiar with the concept already.
Printing TaskPaper 3 documents with Marked 2 CSS templates
A script for printing TaskPaper 3 documents via Marked 2 using some automation and CSS magic.
AnimateMate - Animation Plugin for Sketch
Create animations directly in Sketch.
WrapAPI: APIs for the whole web
Build an API on top of any existing website or find an API for a site that you need.