Winter words of Wisdom

No matter how tired you are of putting on your long johns and your flannel lined jeans and your down vest and your insulated snow pants and your wool scarf and hand-knit hat and thinsulate gloves and micro-fiber parka and felt-liner muck lucks … Put them on. It’s cold outside.

Use sips and python to create vector-based AppIcon for iOS and OSX

I was surprised to see that Xcode does not make it easy to build all the various icon files for AppIcons for Mac OS and IOS. A few tools have been whipped together, but I’m not a fan of needing to install a whole new GUI app just to solve a simple problem. I’m also not a huge proponent of python, but it’s one of the scripting languages that natively supports JSON — which is part of how Apple’s implemented .xcassets (look inside you’ll see a file called Contents.json). So here is my solution — you’ll need to customize it for your own project. This particular project has two different AppIcon.appiconset entries in the xcassets file.

Note that this script re-writes the Contents.json file, to normalize the file naming. By default if you drag-and-drop files into Xcode it just adds -1 and -2 etc.. to the name, which is lame.

Whenever you update the icon (hardcoded here as a file called ‘icon.pdf’) re-run this script and the icon for you Mac and/or iOS app will update!

import re
import json
from subprocess import call
from pprint import pprint

for iconset in ['Design Show Server/Images.xcassets/AppIcon.appiconset', 'Design Show/Images.xcassets/AppIcon.appiconset']:
	json_data=open(iconset + '/Contents.json')
	newdata = []

	data = json.load(json_data)
	for img in data["images"]:
		size = int(re.sub(r'x.+$','', img["size"]))
		filename='{idiom:s}_{size:d}_{scale}.png'.format(idiom=img["idiom"],scale=img["scale"],size=size)
		filepath='{iconset:s}/{filename:s}'.format(iconset=iconset,filename=filename)
		if img["scale"] == '2x':
			size = size * 2
		newdata.append({ "filename" : filename, "size" : img["size"], "idiom" : img["idiom"], "scale" :img["scale"] })
		print('{filename:s} {size:d}'.format(filename=filename,size=size))
		call(['sips', '-s', 'format', 'png', '-Z', str(size), '-o', filepath, 'icon.pdf'])
	json_data.close()
	contents_file = open(iconset + '/Contents.json', "w")
	contents_file.write( json.dumps({ "images" : newdata, "info" : { "version" : 1, "author" : "andy's python script" }}) )
	contents_file.close()

Here’s a gist:

How to move commits after git filter-branch

I’ve read that you’re supposed to be able to use git rebase to move commits from an old repo to a one after using git filter-branch. But I couldn’t get that to work.

The backstory: Our repo was bloated because we started by forking a different project, and then deleted unneeded parts. This was an easy way to get started, but we ended up with all the history of the old project. So I ran git filter-branch and some other tools to clean up the history and remove empty merge commits. While I was preparing that, the rest of the team kept working on the old repo.

So I had to move those commits the rest of the team made onto the new, filtered repo. I used git format-patch and git am. Like this (assuming cwd is the new repo):


( cd ../old-repo; git format-patch --stdout -k commit id on old-repo of last shared commit ) | git am -k

Puppies

A new phase in my life starts…

20140218-091613.jpg

Leo (short for Leonard, in honor of Leonard Nimoy) on the left, and Chester on the right.

20140218-091635.jpg

Me with Leo (Leo has the science-officer blue collar).

20140218-091656.jpg

These best buds comforted each other on the scary ride from the farm outside of New Ulm where they grew up.

XMLHttpRequest access-control-allow-origin cocoa webview

Yes, those are the search terms that had me scratching my head for several hours today…

You see, once upon a time, we trusted each other on the internet. Internet browsers were built optimistically, that no one would try to do foolish things or cheat anyone.

And then came cross-site scripting attacks. That’s where a nice site, like a banking site, gets attacked remotely simply by virtue of someone making an exploit in a comment field or some other innocuous thing. The browser would start sending data to another computer. That is bad.

So browsers got less trusting. They won’t let you send data to another computer unless that computer says it’s okay. (Wait.. what? Isn’t that backwards?) Oh, ok, so that kind of attack is still possible.

But what it does do is protect you from fake sites (e.g. a domain name where they start out recognizable, like www.mybank .. but then instead of going to dot-com, they go to dot-flibbertygibbet.com..)

But today I wasn’t trying to steal your credit card numbers. Honest. I was trying to make a webview control in a Mac app send some data to a server. It was almost working but I kept getting the error


access-control-allow-origin

Searching the internet wasn’t helpful. But I finally found the answer:


[WebView registerURLSchemeAsLocal:request.URL.scheme];

This was really handy, because I was using NSURLProtocol to deliver content via a custom sheme anyhow. But that’s a story for another day.

I hope someone finds this useful.