Javascript?

Intro

Javascript was the first language I dabbled in. Mostly that involved hooking into onClick events and change the colors of various websites I was building. If only I could track down internet archives of those free geocities and angle fire sites... Anyway, I went to school, learned Java, started getting paid to write Java, learned some ruby (thanks to Why's poignant inspiration), went back to school, learned some python, learned some rails, and started hacking together some javascript since that's the lingua-franca of the web. I wrote some javascript hacks to put various cool things on small website projects (https://github.com/iancw/bus-tracker), (https://github.com/iancw/uview), (https://github.com/iancw/mountain-weather). At some point, the project starts to get bogged down with disorganization. In small projects, you can get by without much organization. But as it grows larger and cooler and you start to want to do more with it, you hit a productivity wall. Bus tracker (https://github.com/iancw/bus-tracker) / (http://bus-tracker.herokuapp.com) is at this point. It's got a bit of javascript spaghetti code, that squeaks its way through the rails asset pipeline, uses liberal global variables (some of which are inserted in the rails layout...), has zero unit tests, but got the job done for our class assignment.

Now that I'm picking it back up and using it as a playground for experimenting with mapbox, it seems like a good time to understand Javascript. I understand how to write a function, and even make an AJAX call, but I have little clue about turning out a sane codebase in javascript. Testing? Encapsulation? Are these possible? Also, what are the buzzwords and frameworks...node.js, angular.js, jquery...what are the cool kids doing in the javascript world these days?

The next few blog posts will be my notes and thoughts as I try to come up to speed on the state of Javascript.

Node.js

It's a runtime. Built on chrome's javascript engine. It was created in 2009. it has a package manager: npm. It's server-side javascript. Not client side seemingly. Everyone's making a big deal about it's non-blocking I/O. It sounds like it shines in highly interactive, websites; a replacement for flash and applets.

Resources to follow up on:

- http://www.toptal.com/nodejs/why-the-hell-would-i-use-node-js
- http://www.toptal.com/javascript/guide-to-full-stack-javascript-initjs

Ruby, Gruff, Rmagic, imagemagick, ghostscripts, fonts, ARG!!!!

I'm just trying to graph some bank balance history with ruby, because apparently all personal finances apps for OSX suck. Ruby is way nicer than python, although it doesn't have numpy. But numpy arrays aren't as great with heterogenous data, so I'd have to loop through it all anyway. So why not use ruby, surely I can make a line graph easily?

Theoretically gruff solves the problem, if you can get rmagick installed right.

gem install rmagick

All is well.

But when I run my program...

iMac:simple-banking$ ruby quick-test.rb
/usr/local/Cellar/ruby/2.1.0/lib/ruby/gems/2.1.0/gems/gruff-0.5.1/lib/gruff/base.rb:1142:in `annotate': unable to read font `/usr/local/share/ghostscript/fonts/n019003l.pfb' @ error/annotate.c/RenderFreetype/1126: `(null)' (Magick::ImageMagickError)
from /usr/local/Cellar/ruby/2.1.0/lib/ruby/gems/2.1.0/gems/gruff-0.5.1/lib/gruff/base.rb:1142:in `annotate_scaled'
from /usr/local/Cellar/ruby/2.1.0/lib/ruby/gems/2.1.0/gems/gruff-0.5.1/lib/gruff/base.rb:888:in `draw_no_data'
from /usr/local/Cellar/ruby/2.1.0/lib/ruby/gems/2.1.0/gems/gruff-0.5.1/lib/gruff/base.rb:445:in `draw'
from /usr/local/Cellar/ruby/2.1.0/lib/ruby/gems/2.1.0/gems/gruff-0.5.1/lib/gruff/line.rb:174:in `draw'
from /usr/local/Cellar/ruby/2.1.0/lib/ruby/gems/2.1.0/gems/gruff-0.5.1/lib/gruff/base.rb:424:in `write'
from /Users/will/src/simple-banking/play.rb:46:in `graph_balance'
from quick-test.rb:4:in `

'
^C

These guys propose a solution: http://rubyjunction.us/issues-with-imagemagick----unable-to-read-font, who references https://garrickvanburen.com/archive/installing-imagemagick-rmagick-on-os-x-10-6-snow-leopard/. But that's all pretty overkill. I have home-brew set up, with imagemagick and ghostscript and rmagick and everything installed. I don't want to run some guy's script to re-install everything outside of home-brew.

Finally I find this http://superuser.com/questions/324980/how-do-you-re-install-a-package-with-homebrew-mac, which helpfully includes the note 'Some tools will complain unless the ghostscript fonts are installed to /usr/local/share/ghostscript/fonts'. Yes! That is my problem! But reinstalling imagemagick with fontconfig didn't solve that problem.

Then this guy http://stackoverflow.com/questions/7412208/imagemagick-and-os-x-lion-trouble suggests building ImageMagick from source with the --with-gs-font-dir=/usr/local/share/ghostscript/fonts. Does that tell imagemagick where the fonts are? Or does it put fonts there? I'm trying...

brew reinstall imagemagick --with-fontconfig --with-gs-font-dir=/usr/local/share/ghostscript/fonts

...not sure if home-brew passes along the arguments like that. Appears not.

Wow, well, finally something worked. Who knows how. I still have no fonts in /usr/local/share/ghostscript. I suspect the step that finally fixed things was, after installing imagemagick --with-fontconfig, uninstall the rmagick gem and re-installing it.