09 1 / 2013

Building GraphicsMagick on OSX

Because I’m doing this again, and will never remember next time around…

Install XCode if needed

Install target image format libs and any other dependencies first, as they get included automatically when you compile GM. For each lib, it’s generally a repetition of the following:

  • Download and unzip
  • On the command line, from each lib’s folder, run: ./configure && make && sudo make install

GIF support is built-in. Other commonly needed libs:

NOTE: At this time, building GM with PNG support throws the following error on OSX:

Undefined symbols for architecture x86_64: “_png_set_check_for_invalid_index”, referenced from: _WriteOnePNGImage in libGraphicsMagick.a(magick_libGraphicsMagick_la-png.o) _ReadOnePNGImage in libGraphicsMagick.a(magick_libGraphicsMagick_la-png.o)

So even though it should work, currently I have to explicitly build GM with PNG support disabled just to get it built, as shown below.

Now install GraphicsMagick. Download the current release.

For OSX, You seem to have to compile using clang, rather than XCode’s default of LLVM. So instead of the default sequence shown for libs above, you have to set the CC flag when configuring (in addition to disabling PNG, for now):

./configure CC=clang --with-png=no
make && sudo make install

If there are any issues, or if you install new add-on libs later, you can always rerun the above commands.

Finally, verify that this actually worked (assuming X11 is installed): gm display

Also verify each expected image format by passing image paths:

  • gm display foo.gif
  • gm display bar.jpg

And don’t forget to cross your fingers!

26 1 / 2012

My UTF-8 Byte Order Mark (BOM) Adventure

Another random issue that I resolved earlier with the help of the Internet…

For quite some time now, I’ve had one particular JavaScript file in Extensible that, after every run through my build script, would come out the other side with a garbage character at the top of the file. When running it in the browser the page would choke with a strange “ILLEGAL CHARACTER” error showing the following arcane string: 

I never even knew where to begin with this, and frankly just assumed it was a bug in the Java-based build tool. I’ve been manually removing that character after my builds, well, for way too long. Tonight I finally decided to fix it, and the brilliant idea struck me — how about Googling “”? Well, duh, of course that led me immediately to many explanations of the good old UTF-8 Byte Order Mark, which is:

“Character code U+FEFF at the beginning of a data stream, where it can be used as a signature defining the byte order and encoding form, primarily of unmarked plaintext files. A BOM is useful at the beginning of files that are typed as text, but for which it is not known whether they are in big or little endian format—it can also serve as a hint indicating that the file is in Unicode, as opposed to in a legacy encoding.”

OK, awesome. All of my files are already encoded as UTF-8, apparently without byte order marks, so I have no clue how this one file got one inserted. How to get rid of it?

I use Aptana as my JavaScript editor, so I tried converting the encoding, but turns out there is no explicit option to encode without BOM, so Apatana silently ignores the existing BOM regardless of the encoding (apparently it’s a general Eclipse issue).

A little more Googling led me to a pointer that in Notepad++ you can explicitly encode to UTF-8 without BOM. Although I work on OSX I use Windows VMs for testing, so I cranked up Parallels, copied my script into Windows 7, downloaded Notepad++, converted, copied back, and presto — problem solved! There’s undoubtedly a way to do the conversion in OSX, but this was easy enough and it worked.

Yet another completely useless factoid that was hard-won, and that I’ll almost certainly forget by tomorrow morning.

21 12 / 2011

Markdown + Urls with Parentheses

Yet another completely random topic… I ran across this when trying to link to a resource on Microsoft’s MSDN site from a Markdown document. The link for the page is:

http://msdn.microsoft.com/en-us/library/dd633694(v=exchg.80).aspx

which as you can see, readily confuses Tumblr as well, which uses Markdown during editing and converts it automatically to the broken HTML seen above. The syntax for defining a link in Markdown looks like this:

[some link](http://some-url.com)

which would then render the link like so: some link

Since the url portion of the link is delimited by ( and ), adding parentheses into the url string confuses the Markdown parser (and different Markdown parsers may actually parse it differently).

The solution is simple, though maybe not obvious — you have to HTML-encode the parentheses when using them in a Markdown link. The url-encoded value for ( is %28 and ) is %29. So our fixed link now looks like this:

[MSDN page](http://msdn.microsoft.com/en-us/library/dd633694%28v=exchg.80%29.aspx)

which now renders and functions as expected: MSDN page

(By the way, who even uses stupid urls with parentheses in them? Microsoft, once again, making the web just a little bit harder to work with. Thanks!)

Tags:

Permalink 21 notes

19 12 / 2011

Github Font Issue on Chrome for Mac

For weeks now, I’ve had the issue, only on the combination of Chrome 16 + Mac OSX 10.7 + Github + my MacBook Pro (I do not have this issue on my desktop Mac Pro, or in other browsers) where the font used for code on Github.com (e.g., for stuff like this) was displaying as the default browser font of Times New Roman. Let me tell you, Times is a painful font for web viewing in any context, but for code it’s downright unreadable.

After a bit of Googling, I ran across this exact issue on the Ask Different site. After using the recommended command line commands to reset my machine’s font cache (who knew such a thing even existed?) I was back to a default monospaced font, at least (Courier, ugh).

The first-choice font for code on Github is Bitstream Vera Sans Mono, a lovely monospaced font that (I thought) I had installed already, but apparently I didn’t (or it had gotten itself removed somehow). So I downloaded and installed it manually, re-cleared my font cache, restarted Chrome, and voilà, back to beautiful code.

Random.

[UPDATE: April 10th, 2012]

I had a similar issue tonight, except instead of Times New Roman, this time I opened Github to find this lovely display:

Luckily, I was able to run the same simple commands as last time to reset the font cache, then I restarted Chrome and was back in business. For convenience next time this happens, here are the commands:

$ sudo atsutil databases -remove
$ atsutil server -shutdown
$ atsutil server -ping

If this helps you, please go and up-vote this question, as that person actually figured it out for the rest of us.

09 12 / 2011

Fixing a Stuck VM

My Parallels virtual machine got stuck in a “stopping” state earlier (after an aborted reboot of my physical machine) but it would never stop, and could not be restarted. Luckily this worked like a charm.

11 10 / 2011

Owning it

Owning it

27 8 / 2011

Node Server Kill/Restart Script for OSX

There are times when it would be convenient to kill a running node server and/or restart it in an automated fashion, by name rather than by process id. It’s easy enough to kill a process in Linux, but first you have to find it. It’s simple to list all active process, filtering based on part of the process name like so, assuming a node server named “myserver”:

    ps ax | grep myserver

If myserver is indeed still running you’ll see output like this:

45727 s000  T      0:00.02 sudo node myserver
45728 s000  T      0:00.15 node myserver
45794 s000  R+     0:00.00 grep myserver

Once you know the process ID (PID) it’s a simple matter of killing it:

    sudo kill -9 45728

So just kill the process by id, and then you’re good to restart myserver. [Note: The -9 (or -KILL) switch is not always required, but was in my case. YMMV.]

Of course, each time you restart the server the process is assigned a unique PID, so if you have to kill the new process you first must find it then kill it by the new PID. In some cases this can prove inconvenient, e.g. if you want an automated clean up or restart script, say as part of a CI process.

But wait, I can hear you say, what about the awesome pkill command that can kill a process based on regex matching? I agree, that is awesome indeed — unfortunately pkill is not available on OSX. There are various alternatives, most of which seem hacky at best. You can also install an implementation of pkill (among other things) via proctools, but I really wanted to solve my problem without having to make modifications to my system first.

I finally ran across this answer on StackOverflow which gave me the basic command I needed, and from there it was a simple matter of wrapping that up into a reusable shell script.

Node Kill

It’s a very simple shell script that kills a node server by name (not PID) and optionally restarts it in a single command. For example:

    sh kill.sh -r myserver

That will terminate the ‘node myserver’ process(es) and automatically restart the server for you, simple as that.

The code is available on Github, and any suggestions for improvement are welcome.

Tags:

Permalink 18 notes