All posts by Philip Regan

Cape Cod

I have been told that the part of Cape Cod where I am staying is considered the “Irish Riviera.” I’m not sure whether this is based on a misunderstanding of what comprises the Riviera or the Riviera has been knocked down a few notches over the years. I don’t think I have ever seen a denser concentration of ice cream, pizza, and seafood than here. Seeing signs like “Finest Quality Fried Seafood” is laughable. The food here is, in a word, shit.

Cape Cod is nice, but it’s not “every summer for multiple generations” nice. If anything, Cape Cod is seasonal townie hell.

No turning back

“The brave things in the old tales and songs, Mr. Frodo: adventures, as I used to call them. I used to think that they were things the wonderful folk of the stories went out and looked for, because they wanted them, because they were exciting and life was a bit dull, a kind of a sport, as you might say. But that’s not the way of it with the tales that really mattered, or the ones that stay in the mind. Folk seem to have been just landed in them, usually – their paths were laid that way, as you put it. But I expect they had lots of chances, like us, of turning back, only they didn’t. And if they had, we shouldn’t know, because they’d have been forgotten.”
The Lord of the Rings, J.R.R. Tolkien

#hashtagvomit

#hashtagvomit is when the number and length of hashtags in a social media post is equal to or greater than the length of the content itself.

Whether or not the post in question is good or bad is irrelevant. I don’t regard hashtags as content, but rather a subtext to the content, a type of metadata intended for human consumption. Hashtags ought to be used in the same manner as exclamation points in writing. To wit…

If a sentence really has something of importance to say, something quite remarkable, it doesn’t need a mark to point it out. And if it is really, after all, a banal sentence needing more zing, the exclamation point simply emphasizes its banality!
Notes on Punctuation, by Lewis Thomas

Sleep as a Competitive Advantage

Too many of us continue to live by the durable myth that one less hour of sleep gives us one more hour of productivity. In reality, each hour less of sleep not only leaves us feeling more fatigued, but also takes a pernicious toll on our cognitive capacity. The more consecutive hours we are awake and the fewer we sleep at night, the less alert, focused and efficient we become, and the lower the quality of our work.

The research is overwhelming that the vast majority of us require seven to eight hours of sleep to feel fully rested, and only a small percentage require less than seven. The problem is that we kid ourselves. “Like a drunk,” the Harvard sleep expert Charles A. Czeisler wrote, “a person who is sleep deprived has no idea how functionally impaired he or she truly is. Most of us have forgotten what it really feels like to be awake.”
NY Times: Sleep as a Competitive Advantage

For me, nothing beats a twenty minute nap in the afternoon, maybe thirty minutes. Anything more than that is of little to no benefit. But that twenty minutes can make all the difference in the world for the rest of my day.

I think sleep is really only part of the solution to good productivity, and that exercise and a reasonable diet are needed as well for sleep to be its most effective. I say, “reasonable diet” in that there only a relative few out there that eat truly good all the time; some foods aren’t good for the waistline, but they are good for soul and are therefore irresistible.

I have been working on my health for the past several weeks by working through an exercise regimen from Nerd Fitness. I work out five days a week on average, for an average thirty minutes a day. It’s a well packed thirty minutes prioritizing intensity over time, and within only a couple weeks I found benefits in regards to how I feel overall. Even those nights where I only could get five to six hours of sleep I felt better than before I started working out.

Bloombergview.com: Missing E-Mail Is the Least of the IRS’s Problems

Such policies indicate either an agency that is not concerned with preserving good audit chains or one that has an extremely penny-wise, pound-foolish approach to IT policy. At prevailing wages—and hard drive prices—it is a waste of money to force even your lowest-level employee to spend time painstakingly deleting or archiving e-mails. If IRS staffers don’t have anything better to do with their time, then the IRS needs fewer staffers, not stricter mailbox policies.

In the case of a government agency, however, it’s especially troubling. Records pertaining to agency decisions are supposed to be systematically archived forever. I’m not saying that the IRS’s e-mail retention policy is uniquely bad in the federal government, only that whatever the current practice is, the IRS did not preserve nearly as much as one would like in a representative, transparent democracy.
Bloombergview.com: Missing E-Mail Is the Least of the IRS’s Problems

Apple hijacks Unix headers into Xcode in Mavericks

I am currently taking a class on Unix systems programming. While following along with lecture, the professor stated that almost always the header files needed for our type of work are located at /usr/include. However, that directory does not exist on my brand new Mavericks MacBook Pro. I have learned (after much searching the web) that the header files are now here:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr

After doing some more research, I found that to get those Unix header files back into /usr/include, one has to install Xcode’s command line tools. But, in order to get those, one has to be a registered member on Apple’s developer website. Not necessarily a paying member, but registered.

I was once a paying member for Apple’s developer tools but I gave it up because I was not actually using everything that was made available. My focus changed and the annual $99 was going to waste. In fact, because of that and that Apple has so much of their Cocoa documentation available externally for free, my need to log into their website has decreased over time to my not touching it in over a year. Now I am jumping through the hoops to figure out which account I was using and what was the password, but that is turning out to be harder than expected for a variety of reasons on Apple’s side, the servers not propagating my Apple ID resets to the developer site being one of them. Yes, I should have done a better job of recording my information, but a simple password reset shouldn’t be this hard either. At this point, I will likely just create a new account solely for getting me what I need.

I have no idea when Apple hijacked the header files, and i can understand the logic and convenience of doing so for tool updates, but knowing what little I do about Unix, hijacking seems to be anathema to the Unix culture. Apple has made my morning nothing but hassle trying to get this fixed and I will have an assignment due soon. So, cheers for that, Apple.

UPDATE: I wound up creating an account solely for the developer account, and it was, as expected, faster and easier than mucking about with a bunch of password resets. Once I did that, getting the command line tools was not straightforward though not hard (Xcode > Open Developer Tool > More Developer Tools… which then kicks you over to a downloads page on the developer website, with registration required for access).

As for my comment about the new default header location being anathema to Unix, I realize now that’s not necessarily true. If anything, Apple can do whatever they want with their distro. But the fact remains based on everything I have read so far that there are some clear expectations about there things ought to be and the header file location is one of them. But at least now I can establish a workflow where I can use the muscle of Xcode to develop and then confidently test outside before submission.

Facebook Paper

Paper presents user updates as “stories”: captions overlaid on large-format photos, auto-playing videos, and even long or short text screeds all in an edge-to-edge, full-screen format. The default “section” in the app is the user’s Facebook news feed, but users can pull new sections up from a set of cards, such as “Headlines” or Tech,” and browse between them in one pane.

“Each section includes a rich mix of content from emerging voices and well-known publications,” Facebook says. This gives the biggest clue to the real intended creators for paper: brands, be they news outlets or celebrities.
Ars Technica: Facebook’s Paper is Facebook without the Facebook

Oh, look, yet another proprietary digital publishing platform targeted at publishers. How quaint. Here, let me add this to my pile of fifty or so I have over here.

Applescript: Getting unique items in a list update

I love getting questions about the contents of, or topics related to, my site. Most recently, I was emailed a question about one of the older functions I have in the Applescript section. In particular, it was one for getting unique items in a list. Here’s the function…

on GetUniqueItems(sourceList)
	set itemCount to (get count of items in sourceList)
	set compiledList to {}
	--get the first item to kick off the list
	repeat with x from 1 to itemCount
		set itemFound to false
		set itemX to item x of sourceList
		if x < itemCount then
			repeat with y from (x + 1) to itemCount
				set itemY to item y of sourceList
				if itemY is itemX then set itemFound to true
			end repeat
		else
			repeat with y from 0 to (itemCount - 1)
				set itemY to item y of sourceList
				if itemY is itemX then set itemFound to true
			end repeat
		end if
		if itemFound is false then
			set end of compiledList to itemX
			exit repeat
		end if
	end repeat
	--if no items are found
	if (get count of items in compiledList) is 0 then
		return compiledList
	end if
	--find the rest of the unique items
	repeat with x from 1 to itemCount
		set itemFound to false
		set itemX to item x of sourceList
		set resultCount to (get count of items in compiledList)
		repeat with y from 1 to resultCount
			set itemY to item y of compiledList
			if itemY is itemX then set itemFound to true
		end repeat
		if itemFound is false then set end of compiledList to itemX
	end repeat
	return compiledList
end GetUniqueItems

The question was focused on why I go through the source list more than once. As soon as I saw the function after the question, I knew they were right that something was wrong. My answer essentially explained that this was one of the first useful home-brewed functions I wrote, and since it worked, it stuck, as working code is wont to do. But, honestly, I’ve reviewed this code a dozen times and it has me completely baffled as to how it works. I think there is even a whole block on there that can come out and nothing would change.

I started writing my first Applescripts in 2005, which was also my first serious foray into programming. The last time I thought about if...then statements was in high school writing BASIC for the Commodore 64 in high school. This function, according to my notes, was written in 2007 when my needs and skills were becoming more robust. This function is currently in use in several scripts today with nary an error. But, nine years of experience later and immediately that function is absolutely cringe-worthy (though only to a point considering when I wrote it), so I rewrote it. Et voilà…

on getUniqueItems(src)

	set srcCount to (count src)

	set unq to {}

	repeat with x from 1 to srcCount

		set srcItem to item x of src

		set unqCount to (count unq)
		set match to false

		repeat with y from 1 to unqCount
			set unqItem to item y of unq
			if srcItem = unqItem then
				set match to true
			end if
		end repeat

		if match is false then
			set end of unq to srcItem
		end if

	end repeat

	return unq

end getUniqueItems

Hindsight being 20/20 and all that, this a “duh!” moment. There are a couple important things to note about this.

First, my test data for these types of functions is reliable but small. This is O(n2) on the low-end of things, but almost invariably Applescripts very rarely ever deal with data sets large enough where O(nk) has enough of an impact to get a coffee and sandwich while waiting. My personal experience and preference is that if that were the case, then I need to go find a more appropriate tool for data prep.

Second (and last), this block…

set unqCount to (count unq)
set match to false

repeat with y from 1 to unqCount
	set unqItem to item y of unq
	if srcItem = unqItem then
		set match to true
	end if
end repeat

if match is false then
	set end of unq to srcItem
end if

…could be replaced with this common Applescript hook…

if unq does not contain srcItem then
	set end of unq to srcItem
end if

The only problem with this, as I see it, is when trying to compare custom data types as opposed to core data types. This is great if I only ever worked with Applescript’s core data types, like string, number, date, and the like. But almost all of my Applescript code has been targeted to Adobe’s Creative Cloud, which brings a wealth of custom objects with loads of properties with which to work. I think leaving in the extra code (and any possible hits on speed since this not baked into the language like contains) is reasonable for the sake of easy customization later. By way of example, this…

-- compare memory addresses
if srcItem = unqItem then

…becomes this in a pinch…

-- compare object properties
if foo of srcItem = foo of unqItem then

…or even…

-- deep comparison
if my customCompare(foo of srcItem, foo of unqItem) then

So, a bit of extra code for the win. I suppose I could set up a hash table implementation to improve upon the O(n2)O(nk) range of complexity, but with Applescript work, again, it’s really not worth it.

That was a really great question on a number of levels. Not just that this shows that people actually read the site on occasion and finds something useful, which is the core goal of the site (this blog is really more of just a place to vent that offers me more flexibility than other blogging sites or social media) but also to be compelled to review and improve old code and find just how far I have advanced over the years. Win-win.