Tag Archives: OS X

Swift Optimization

I learned a hard lesson today: to make Swift really fast you have to know what you’re doing. You can’t just slap some code together and expect it to be zippy without understanding some of how Swift was designed and how it works. There is a very good presentation by some of the team members that built Swift here. My initial takeaway was that it was important to finalize any classes you didn’t plan on subclassing, incrementally check the timing analyzer, and finally, employ whole module optimization.

Continue reading Swift Optimization

Matrix Inversion Using Swift and Accelerate

I found out how to invert a matrix on SO, but I didn’t understand the solution, so I thought I’d talk more about it here. First of all, there isn’t a one-off inverse function in the Accelerate framework. You need to calculate the LU facotrization first using dgetrf_(), and then plug that data into dgetri_() to calculate the inverse.

Continue reading Matrix Inversion Using Swift and Accelerate

Creating Icons for Mac Apps

I found this so helpful on StackOverflow, I thought I’d re-post it here for my personal reference. The snippet below is used to take a 1024-by-1024 pixel PNG file named Icon1024.png, and create smaller resolution copies in an iconset directory, which can be used later when you deploy your app.

mkdir MyIcon.iconset
sips -z 16 16     Icon1024.png --out MyIcon.iconset/icon_16x16.png
sips -z 32 32     Icon1024.png --out MyIcon.iconset/icon_16x16@2x.png
sips -z 32 32     Icon1024.png --out MyIcon.iconset/icon_32x32.png
sips -z 64 64     Icon1024.png --out MyIcon.iconset/icon_32x32@2x.png
sips -z 128 128   Icon1024.png --out MyIcon.iconset/icon_128x128.png
sips -z 256 256   Icon1024.png --out MyIcon.iconset/icon_128x128@2x.png
sips -z 256 256   Icon1024.png --out MyIcon.iconset/icon_256x256.png
sips -z 512 512   Icon1024.png --out MyIcon.iconset/icon_256x256@2x.png
sips -z 512 512   Icon1024.png --out MyIcon.iconset/icon_512x512.png
cp Icon1024.png MyIcon.iconset/icon_512x512@2x.png
iconutil -c icns MyIcon.iconset
rm -R MyIcon.iconset

The next to last line uses the iconutil utility to convert an iconset into an icns file, but it can also work the other way. (See man iconutil for more information.)

Using app2py for OS X Distribution

I thought that .pex files were the way to go for distributing Python applications to OS X users, but it was only partially successful. For one, users needed to reinstall Python with Homebrew, which isn’t difficult, it’s just awkward explaining to people that the Python distribution that ships with Mac isn’t the same Python distribution that exists in the wild. Their next question is invariably, “how will this affect the rest of my system?” I can’t answer that. I can’t guarantee that things will be future-proof.

And then I found app2py (or five dollars) which creates a Mac application bundle out of a Python script. It worked like a charm. The best thing is that you don’t have to write a stupid setup.py file, it writes one for you. That’s five minutes of your precious time you can look at cat videos with, or whatever.

You can install this using pip, so that’s cool. Next, you do as the tutorial explains,

py2applet --make-setup MyApplication.py

This will create a setup.py file. Finally, for deployment, you build the distribution with a non-Mac Python installation. (If you haven’t already run brew install python you’ll want to run that.) My brew installation of the Python landed somewhere in /usr/local/Cellar/....

/usr/local/Cellar/python/2.7.8_2/bin/python setup.py py2app

This will create a standalone Python application that you can distribute painlessly to your Mac colleagues.