Archive for the ‘Apple’ Category

Swift Dictionaries are Always Value Types

Tuesday, February 3rd, 2015

Swift

More reading in The Swift Programming Language and I've come to the part about Arrays and Dictionaries. Specifically, a dictionary is treated as a Valu e, and that means that it's copied on every assignment and on all function or method calls. The significance of this, to me, is profound. One of the singularly most useful data structures for a coder is the dictionary (the other is the array), and to find out that passing around a dictionary makes a copy on each method call and on each assignment.

In the CryptoQuip codebase, we create a map of all the known words - where the key is the pattern of the word, and the value is an array of all known words with that pattern. As we run through the list of words (a file), we calculate it's pattern, and then add it to the array in the dictionary for that pattern. In clojure, we really compute all the patterns for the words, and then group them by their patterns.

We then pass this dictionary around to make it simple to find the possible words that a cypher text word could be. If the docs are as they have been written:

Whenever you assign a Dictionary instance to a constant or variable, or pass a Dictionary instance as an argument to a function or method call, the dictionary is copied at the point that the assignment or call takes place.

yet they also try to say this isn't an issue:

The descriptions below refer to the “copying” of arrays, dictionaries, strings, and other values. Where copying is mentioned, the behavior you see in your code will always be as if a copy took place. However, Swift only performs an actual copy behind the scenes when it is absolutely necessary to do so. Swift manages all value copying to ensure optimal performance, and you should not avoid assignment to try to preempt this optimization.

Sadly, StackOverflow isn't a lot of help, and this includes talking to someone in the Swift Language group in Apple. The advice appears to be: Wrap it in a class.

The reason being that all Classes are pass-by-reference as opposed to pass-by-value. While this certainly can solve the problem, it makes something that should be very simple a lot harder. I can see how to do this, and should we move ahead with the CryptoQuip solver in Swift, it can be done, but it seems like a hack.

Kinda seeing some of the cracks in the Swift language... not ideal, but it is what it is.

Swift Structures are Always Pass-by-Value

Tuesday, February 3rd, 2015

Swift

I've been reading The Swift Programming Language this morning just to stay sharp, and because I've read several accounts of where Swift out performs ObjC, and the ruby-like nature of Swift means that it might be a lot faster to code up. So I was reading more...

What I found was pretty surprising about the differences between Structures and Classes - Structures are always copied when they are passed around in the code. This means that there is no way to pass-by-reference a struct to a function or method, and this will certainly modify where they can be used.

As a counter-point, in C++, classes and structs are basically the same thing. There are very minor differences, at best, and yet here in Swift, it's a fundamental difference that they chose to implement, as opposed to had to implement, and that tells me that there's something they see in Structures that they don't see for classes.

Not quite sure what that is, but immutability could certainly be one thing - passing by value allows the value(s) to be modified, but the caller's values are never touched. There might also be something in the NSPoint structures as well - something where they are looking at very simple data elements with no methods on them. Yet this means you can't have a function that modifies a passed-in structure.

Very interesting. Not sure where they are going with this, but it's something to look out for.

Adium 1.5.11hgr5894, MSN, and OS X 10.10 Aren’t Happy

Friday, December 19th, 2014

Adium.jpg

A while back, just after switching to OS X 10.10 Yosemite, I saw that Yahoo! wasn't at all happy with Adium. It simply wasn't connecting. Thankfully, there was a known fix in the works, and it didn't take long for someone to build a version and post it online. Soon after that, the Adium developers posted a similar update to their Nightly Builds, and I picked that up to be a little safer.

I have to admit that I'm a little surprised that it took so long, but I was willing to let it go - Adium has been a really great Open Source tool for me over the years, and it's certainly possible that they just got caught up in other things, and didn't have time to make the release.

Now we're in a slightly different situation, and there's a problem with MSN Live:

Adium and MSN

The story is that MSN has changed the accpetable API ids and the one that Adium and libpurple is using is not on the "approved" list. There is another in libpurple now, but the Adium team hasn't picked it up, or hasn't integrated it, or hasn't released it. In any case, it's stalled. Badly.

Now I'm not a big MSN IM user, but it's there, and it's simple to fix, and it's ready to go, so let's get to it, guys. Or let's make it clear that there are no developers to support this, in which case, I'll pick up the mantle, and just do the things that I think need to be done to keep it moving forward.

My fear about this is that the codebase is in horrible shape, and it's hours and hours to figure out anything, and then it's horrible to build, etc. There's also the Colloquy concern - it stopped updating, and then Textual picked up the banner, and I bought that app off the App Store. If someone looks at the sad state of Adium, I see them coming to the same conclusion and making a paid multi-protocol IM client.

Getting Apache 2.4.9 + PHP 5.5.14 Going on OS X 10.10 Yosemite

Thursday, December 18th, 2014

Yosemite

This morning I thought I'd just check on the status of Apache + PHP + Postgres on OS X 10.10 as it was likely that in the update from 10.9, Apple had changed things, and sure enough, they have. But it wasn't all them - Apache has some changes in it as well, so to be fair, getting this all to run is a little more complex than you might imagine, but it's still not all that hard.

Getting PostgreSQL 9.3

As with the previous post I'm using Homebrew and that's made the entire operation a lot smoother. There's no 32-bit/64-bit issue as Homebrew does both, and it builds in on your box, so again, a lovely customized solution with a simple command:

  $ brew install postgresql

It even has a nice, simple informational blurb about how to start/stop and upgrade. Very nice. But now that it's on the box, and ready to roll, let's add in the PostgreSQL support to the PHP 5.5.14 that's installed with Mac OS X 10.10.

Activating UserDir in Apache 2.4.9

The first thing I noticed is that the UserDir extension is not enabled by default, so we need to get that going right away. This enables the code to be run from the development directories, and that's a big time-saver. First, we need to enable the UserDir module in Apache, and then make a specific config file for the user in question. Start by editing /etc/apache2/httpd.conf and line 166 needs to be uncommented to read:

  LoadModule userdir_module libexec/apache2/mod_userdir.so

and then similarly on line 493 uncomment the line to read:

  Include /private/etc/apache2/extra/httpd-userdir.conf

At this point, you need to make sure you have at least one file in the /etc/apache2/users/ directory for each user, like: drbob.conf:

  <Directory "/Users/drbob/Sites/">
      Options FollowSymLinks Indexes MultiViews
      AllowOverride None
      Order allow,deny
      Allow from all
      Require all granted
  </Directory>

where the last line - Require all granted is new as of Apache 2.4, and without it you will get errors like:

  [Thu Dec 18 10:41:32.385093 2014] [authz_core:error] [pid 55994]
    [client fe80::7a31:c1ff:fed2:ca2c:58108] AH01630: client denied by server
    configuration: /Users/drbob/Sites/info.php

Activating PHP in Apache

The mext thing to do is to activate PHP in the supplied Apache 2 with OS X 10.10. This is line 169 in the file - /etc/apache2/httpd.conf and you need to uncomment it to read:

  LoadModule php5_module libexec/apache2/libphp5.so

and then add a new file called /etc/apache2/other/php5.conf and have it contain:

  <IfModule php5_module>
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
 
    <IfModule dir_module>
      DirectoryIndex index.html index.php
    </IfModule>
  </IfModule>

which does all the other PHP configuration in a separate file to make upgrades easy.

Building in PostgreSQL 9.3 extra for PHP 5.5.14

At this point we need to get the source code for the exact version of PHP that Apple ships. This is pretty easy by getting the PHP 5.5.14 source from a mirror and unpacking it into a directory. We then just run the following commands:

  $ cd php-5.5.14/ext/pgsql/
  $ phpize
  $ ./configure
  $ make

at the end of this process, you'll have a file: php-5.5.14/ext/pgsql/modules/pgsql.so and that needs to be placed in the right directory and referenced in the php.ini file.

For Mac OS X 10.10.1, this is accomplished with:

  $ sudo cp modules/pgsql.so /usr/lib/php/extensions/no-debug-non-zts-20121212/

and then edit the /etc/php.ini file to include this new extension by adding the line:

  extension=pgsql.so

Thankfully, the extension_dir is already set in OS X 10.10.1, and we no longer have to set that.

Finishing Up

At this point, a simple restart of apache:

  $ sudo apachectl restart

and everything should be in order. Hit a URL that's a static file with the contents:

  <?php
    phpinfo();
  ?>

and you should see all the details about the PHP install - including the PostgreSQL section with the version of Postgres indicated:

Postgres + PHP

All is working once again!

Development Set-Up at Home

Thursday, December 18th, 2014

Thunderbolt

Over break I'm going to be working at home on a few little fun projects, and with my two Thunderbolt displays, I was thinking I might need a hub of some kind, so I went to look for one on the Apple Store web site - just to see what was out there, and what they might cost - if I shopped in town.

I honestly didn't find anything, and then I wondered What's on the back of the monitor? to see if I could chain these together? Turns out, you can. The guy working across from me as two, and they are chained, and I've seen them work just fine. There's even a YouTube video on the set-up.

Very nice!

This will be just what I have when I get started on Saturday morning - if I wait that long. Apple stuff is pricey, yes, but you do really get what you pay for, and this is no exception: one cable to the laptop, driving two 27" displays. Sweet.

Postgres 9.3 and Mac OS X 10.10 Yosemite Upgrade

Thursday, December 18th, 2014

Yosemite

This morning I was looking into yet another Adium problem with MSN Live, and I opened up the Console.app and noticed a lot of messages like this:

  12/18/14 4:08:22.886 AM com.apple.xpc.launchd[1]:
    (homebrew.mxcl.postgresql[52026]) Service exited with abnormal code: 1

and when I tried to check if Postgres was running:

  $ psql -l
  psql: could not connect to server: No such file or directory
          Is the server running locally and accepting
          connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

so it was clear that something was wrong with postgres on my laptop.

To be fair, I haven't really messed with this since going to Yosemite, so I hit DuckDuckGo and it reported this post on StackOverflow, which says that in the Yosemite upgrade, several empty directories were deleted, and all I needed to do was to re-create them and restart postgres.

So I:

  $ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
  $ cd /usr/local/var/postgres
  $ mkdir pg_tblspc
  $ mkdir pg_twophase
  $ mkdir pg_stat_tmp
  $ chmod 700 pg_tblspc pg_twophase pg_stat_tmp
  $ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

and then I could see all the databases on the laptop, and the Console.app showed that things were running just fine.

While I understand that postgres is inefficient as it's running all the time, I still love this database, and it's worth the cycles to have it on my development laptop because it scales to the server room so bloody well.

Problem solved. Whew!

XQuartz 2.7.7 on OS X 10.10.1 Yosemite

Friday, December 12th, 2014

X11.jpg

As I didn't have a lot to do this afternoon, I decided to check on the state of X11 on OS X 10.10.1 - and it's actually not bad at all. I was able to get Quartz 2.7.7 from the download site, and it installed easily enough. All the normal things run, and it's a complete X11 we just need the apps - or in the case of SSH access, getting to a linux machine for the X11 apps on the remote host.

Because I got rid of my home machines with X11 a while back, I'm not sure how much this is going to get used any more, but it's nice to know that it works before I really need it, so that I know I can go to it in a time of need.

Finding the Joy in Life Again

Wednesday, October 22nd, 2014

Great News

I honestly would have put money on the fact that this would not have happened today. Big money.

I'm sitting on the bus riding to work, and I realize that I'm pretty happy without a pain-causing personal relationship in my life. That was a wow! moment. I've been separated for about 2 years, and the divorce is in the works, but I would have bet real money I'd feel horrible for the rest of my natural life. But today... on the bus... for a few minutes... I didn't.

That was huge for me. Huge.

Then I'm in work, updating a few postings with the results of the tests I'd done overnight, and I'm back into the swing of posting like I used to. It's been a long two years, but I'm back to writing about what I'm doing, and it's really helping. I'm feeling like I'm enjoying myself again.

This, too, was huge for me.

I don't expect this to last all day... but the fact that I have felt this way tells me that I need to keep doing what I'm doing - keep moving forward, and then maybe this will come again. And maybe when it comes again, it'll last longer. Maybe.

Adium 1.5.10, Yahoo!, and OS X 10.10 aren’t Happy

Monday, October 20th, 2014

Adium.jpg

Turns out that Adium 1.5.10 and Yahoo! IM isn't happy with OS X 10.10 - it's saying that it can't connect to the Yahoo! IM server and erring out. Normally, this wouldn't be an issue for me, but I've got a few friends that I stay in touch with all the time, and because of their employer, two of them have been kinda off-limits to me for a while - but one finally found his way back to me through Yahoo! IM.

While I'm really loving the changes in OS X 10.10, sadly, with the update, the Yahoo! IM connection has failed to work. And it's not at all helpful in any way:

Bolt Counts

What I've read from the Adium blog is that there is a known fix - but there's a potential security concern, and I'm not at all sure why they are delaying releasing a patch for Yosemite... but they are.

So I'm out of touch with an old friend until I can get an update from Adium. This is one of the issues with Open Source - abandoned software. I'm sure the point is that I can pick it up and fix it, and I might be able to, but it's a pain, and it's something I've come to depend on. In that, I like paying for things.

Upgraded to Mac OS X 10.10 Yosemite

Monday, October 20th, 2014

Yosemite

This morning I just got a little antsy and decided that on my personal laptop, it was time to upgrade it Mac OS X 10.10 Yosemite. I am so glad I did. The flat look - on all the web sites of the reviews - is just what I like. Almost no chrome - no need for it. Smooth visuals on my retina MacBook Pro, but I'm guessing that's the key to this upgrade - having a rMBP. Still... I've got one :), so I'm loving this.

I'm still on the Light treatment as I don't find the transparency at all intrusive or distractive - as I've been using it on MacVim for a while. MacVim was my only concern about working, but that's fine. What I didn't expect was that Adium 1.5.10 could no longer connect to Yahoo! IM. That's not good because I still reach out to Jeremy on Yahoo!.

I looked on the web, and it turns out that this is a known issue with OS X 10.10, and there is a fix for it, but it's not out yet - not even in beta. I'm a little surprised by this as I didn't really dig into what the patch was, but they have been so proactive in the past, I'm surprised that there's no beta out there for this.

After all, this has been out in "general release" for quite a while now, and while they may not want to target each update, it's something else to know there's a fix, and let weeks pass and no beta or update. I guess I'll have to wait.