Google+ Badge

Wednesday, March 27, 2013

Life with a Mac a few weeks in

At my new job my development machine is a Mac. Having been a heavy windows user for the last bunch of years but using a Mac on occasion to do some iOS development the change has been pretty easy.

Initial setup took some time as did learning initial command line options. Really everything else is pretty much just like on a PC. You run Eclipse, Sublime Editor, Chrome, Outlook, Finder, Terminal window, Evernote, a music player and various file viewers for images and PDF files. 

Once configured you just have to learn the proper shortcut keys to pull of frequent operations and off you go. This is a MacBook pro and I have a large second monitor. Everything is really fast.

I have been working on parsing XML and JSON files from security firms. Lots and lots of parsing of large files - will not HUGE but big as in 55+meg in size. I tried a number of JSON parsers and finally settled on Jackson as I needed to do streaming parsing and needed the ability to build simple JSON constructs on the fly as one provider uses JSON for request and response while the other two use standard HTTPS: requests with ?name=value params for requests and XML for responses.

Each API has its own set of oddities. Right now I have everything we need parsing and am using pagination to keep the response sizes to something reasonable. Next step will be hooking it all into the production code. Always good to iron out the bugs with simple test applications first.

At this point I really don't even think about being on a Mac. Sure the frame decorations are a bit different than in Windows but Eclipse looks and operates like Eclipse. Chrome is Chrome and sucked over all my settings, bookmarks and extensions. 

If I need a program I can generally find it but there are a lot less free options than on the Windows. Most things cost something or there is one or two free versions. Most programs have already made a number of decisions for you. Unzip something? Put it right where you unzipped it from. Don't ask where you want to put it. Download something? Yep, already gonna do it to the one directory I have chosen. Not a huge deal. I move things around expo facto but there is a lot more hand holding.

I have been kind of surprised at home much time I have spent in Terminal. Using Mac Ports to install software, dealing with CURL and Python etc. Some of this is for testing the API and some has been to get around Finder limitations. Of course I do the same when in Windows. Not that a normal schmuck would do this, as a developer I tend to need to do odd things.

There has been a lot of learning. I have never used CURL, xml_grep or JSON streaming parsing before. I had limited exposure to Python and Tree based JSON parsing. None of the sample code I have gotten for the APIs has been written in Java meaning I must learn CURL, Python etc. to know enough to convert to our target language. I love to learn so it has been a lot of fun for me. Gives you an appreciation for the other languages and utilities.

Working with vendors keeps you on your toes too. Good to have 3 going at same time otherwise you are waiting on one to respond while you have nothing to do which is never good. Keep me busy. Also allows you to spot differences and similarities in the APIs making some coding go faster. If this was split between 3 people that knowledge would not be shared as easily. I have shared many classes between the projects.

Wednesday, March 20, 2013

Other Mac things I have learned


Show hidden files in any open / save dialog  

As a programmer there are times you need to create files that start with a '.' (period / dot) such as .bash_profile. But what happens when you want to open that file to edit it? The standard Open Dialog does not show hidden or system files.

Press Cmd+Shift+.  (that is the period) when the dialog is open to show all those bonus files.

Change file association

I wanted to open JPG files in Picasa instead of Preview.

Right click on a file and selecte "Get Info"
Change default application to open it with, then click the button [Change All]


Use XML_GREP to quickly pull data from XML files

There are times you are given an XML file and you want to quickly pull small pieces of information out of it. No need to write a full SAX or DOM parser to do that when you can use XML_GREP.

Sample of a record in the XML file
<REPORT_TEMPLATE_LIST>
  <REPORT_TEMPLATE>
    <ID>1537005</ID>
    <TYPE>Auto</TYPE>
    <TEMPLATE_TYPE>Scan</TEMPLATE_TYPE>
    <TITLE><![CDATA[Executive Report]]></TITLE>
    <LAST_UPDATE>2013-03-08T15:37:07Z</LAST_UPDATE>
    <GLOBAL>1</GLOBAL>
  </REPORT_TEMPLATE>
  ...
</REPORT_TEMPLATE_LIST>

Would show:
Executive Report
...

To grab multiple tag values:
xml_grep --text_only --cond 'TITLE' --cond 'TYPE' assetDataReport.xml

Would show:
Auto
Executive Report
...

Remove the --text_only parameter if you want to see the TITLE tag information too.


How to install XML_GREP

 Visit: http://www.xmltwig.org/xmltwig/ and download latest version

  cd XML-Twig-3.42 (use version downloaded here in place of 3.42)
  perl Makefile.PL -y
  make
  make test 
  sudo make install


Format XML file (pretty print)

Let's say you have an XML file that is all one one line or has no indenting and you want to pretty print it. You can use xmllint which is already installed on you Mac to do that. Here I am converting Sample Report.xml to newfile.xml where Sample Report.xml is the original unformatted file and newfile.xml is the indented pretty version of the file.

  xmllint --format --encode utf-8 -o newfile.xml 'Sample Report.xml'  

Thursday, March 7, 2013

What I installed on my Mac at new job

Boy it has been a long and winding road to get the new MacBook Pro into a useful state. I realize Macs are meant to be super easy to use but that gets in the way of power users.

I have learned a lot of new terminal commands, where files reside on a Mac, naming conventions when reading Mac web pages and what not. I will try to share what I can before I forget it all and move on to the next thing.

I wanted to see hidden files. Executing this in terminal allows for that:

defaults write com.apple.finder AppleShowAllFiles TRUE

Change the TRUE to a FALSE to reverse the change.

~/ means your home directory when you are on a web site.

See the first five lines of the clipboard

pbpaste | head -n 5

Terminal is OK but I wanted a tabbed support as I use Console 2 on the PC. I installed iTerm to handle that situation. I also like a semi-transparent background on the terminal as I am generally monitoring things behind it too.

Finder is really not my cup of tea but I was able to get around most of my issues using xtraFinder. While this program is still in beta it fixes the major issues I have with Finder and it is free.

1) Tabs to open multiple directories instead of having multiple windows open on screen
2) Grouping folders first then files. Never understood why Finder does not have this option. Most of the time I am looking for a folder first then a file within second, I don't want to scroll way the heck down to find my Folder. I know I can sort by Kind to get them in group but that still puts them randomly somewhere grouped in a list.

I copied in my music files from a USB key from my Windows box. There was a stupid desktop.ini file left in each album directory. I wanted to delete all of them which on Windows is:

del desktop.ini /s

For the Mac I needed:

find . -name 'desktop.ini' -print -exec rm -fr {} \;

I realize this is a more powerful command but this is a simple thing I need to do a lot and what I had to type to make it happen was not straight forward. I will have that command in my pocket from now on though.

I had to tweak my security settings to allow me to install things not from the Mac Store. Good to stop a normal user from doing this and it was a one time change to make me happy.

Mac Ports seems to be the way to go to install 3rd party products. You need to know the name of what you are installing. You get to type your password a lot as you are using SUDO commands left and right to accomplish this. It works and the web sites are really good at listing the port name you need to use for the install.

Just found you need to do this after installing Xcode and the Xcode command line tools:

sudo xcodebuild -license

If you don't then you will get errors when attempting to install programs.

The company uses VMware Fusion so I had a license. I was able to quickly install Win 7 professional from DVD. Some of the production apps are written in C# thus the need for a VM to run them.

iTunes does not support common audio file formats so I used Adapter to convert music to MP3 so I can listen to it on my Sennheiser wireless headphones. I have had them for a couple of years now and still on first set of rechargeable batteries. While not perfect, an occasional hiccup due to interference, they have served me well.

At the prodding of the other developer who started on the same day as I did I installed Evernote. Nice app to type in random thoughts and to do lists as they hit my brain. I can see all that stuff on my Note II which makes it very easy to remember the crazy list of items I still need to bring in. 

I use Sublime 2 as my text editor. I like it that I have the same editor on my PC at home as on the Mac. Some of the keystrokes are a bit different but I am getting used to that too.

All the other set up was configuring SQL settings, other environment variables, VPN, tweaks to various programs so they operate to my liking and doing web research on my first project and on tools they use here that I am not deeply familiar with yet.

I also need to find out coding style. Seems to be opposite of the last job no matter where I go. I am used to braces on same line but it appears that they are on separate line here. No big deal to me, configure Eclipse to do it that way and get on with life. 

Do wish I had a docking station for the MacBook, unplugging everything to take it home for the night is a bit silly. Was so easy to undock the Lenovo laptop at old job and put it in bag with extra power supply. Not enough USB ports and they seem to trickle charge my phone. I have the external keyboard in one port and my phone in the other leaving zero for anything else.