Code or Die Welcome to my kitchen

Yak shaving tips, Infosec, Astronomy, Gardening

This is my blog. Proud guardian of three cats and two dogs, I currently reside in San Antonio, Texas.

I'm interested in gardening, astronomy, infosec among other pursuits. About this site.

Past and current projects.. You can also browse the blog archive if you like.

Message of the Day: Under construction

Early Coder Reading List

Here is an early coder resource focusing on Ruby, JavaScript and Rails development. As dead tree media tends to obsolescence, latest online editions should be sought out if possible.

Beginner:

Intermediate:

Advanced:

My Sublime Prefs

As a segue from the previous post on setting up the developer environment, I wanted to record my current setup for Sublime Text build 3083. This is not a post that debates the relative merits of this or that text editor. Maybe some other time.

I love Sublime Text. As a tool that I use daily in my chosen profession, I am more than happy to pay for the registered version and support the developers who make it. This should not be taken as a jab at any other text editors, open source or otherwise. Software developers and engineers are known to be obsessively defensive of their chosen favorite tools, most notably text editors.

Now that we have that out of the way, here is what works for me.

I use two machines, a desktop and laptop, so I sync Sublime Text settings via Dropbox. Instructions to do this are located here.

User Preferences

Here are the contents of the synced preferences file:

User/Preferences.sublime-settings

{
  "auto_complete_delay": 25,
  "bold_folder_labels": true,
  "caret_style": "blink",
  "color_scheme": "Packages/Predawn/predawn.tmTheme",
  "ensure_newline_at_eof_on_save": true,
  "file_exclude_patterns":
  [
    ".DS_Store",
    ".tags*",
    "*.pyc",
    "*.pyo",
    "*.exe",
    "*.dll",
    "*.obj",
    "*.o",
    "*.a",
    "*.lib",
    "*.so",
    "*.dylib",
    "*.ncb",
    "*.sdf",
    "*.suo",
    "*.pdb",
    "*.idb",
    "*.class",
    "*.psd",
    "*.db",
    "*.pdf"
  ],
  "folder_exclude_patterns":
  [
    "data",
    ".zeus.sock",
    ".git",
    ".svn",
    ".hg",
    "CVS",
    ".sass-cache",
    ".bundle",
    "bundle",
    ".rbx",
    "script",
    "tmp",
    "log"
  ],
  "font_face": "Inconsolata-dz",
  "font_size": 14.0,
  "highlight_line": true,
  "highlight_modified_tabs": true,
  "ignored_packages":
  [
    "Vintage"
  ],
  "indent_guide_options":
  [
    "draw_normal",
    "draw_active"
  ],
  "line_padding_bottom": 0.5,
  "line_padding_top": 0.5,
  "predawn_tabs_medium": true,
  "rulers":
  [
    80
  ],
  "save_on_focus_lost": true,
  "scroll_past_end": true,
  "shift_tab_unindent": true,
  "tab_size": 2,
  "theme": "predawn-DEV.sublime-theme",
  "translate_tabs_to_spaces": true,
  "trim_trailing_white_space_on_save": true,
  "word_wrap": "true"
}

The usual suspects are here. I am a big fan of matching popular style-guides so I will use “tab size: 2”, and “translate tabs to spaces” enabled. “Save on focus lost” is a life saver as well as a time and sanity saver, especially on large projects.

“Trim trailing white space on save” is pretty self-explanatory, but for more information as to why “newline added on EOF (end of file)” should be used, check out this enlightening post on thoughtbot’s blog that explains the history.

Font

I use Inconsolata-dz, a variation of the superb Inconsolata font that includes straight quotes. I really love it, and can’t recommend it enough. Since I sync my Sublime settings from desktop to laptop and I like to reduce eye fatigue instead of squinting, it is set to a slightly larger font size than normal.

The original Inconsolata font created by Raph Levien is located here.

The Inconsolata-dz variant by David Zhou is available here.

Again, the subject of code fonts is highly contentious among the developer community, so in the interest of brevity I won’t elaborate further here. Maybe another day.

Theme

I use Jamie Wilson’s excellent theme, Predawn, and I follow the recommendations on that page for Markdown editing.

It is naturally available via Package Control.

Packages

Speaking of packages, here are my currently installed Sublime Text packages:

Since I recently reinstalled my OS, I may will definitely find more to download. One that springs to mind is Sublime​Linter and its language-specific packages.

Key Bindings

Here is the contents of the synced Key bindings file: User/Default (OSX).sublime-keymap

[
// Rails ERB tags
{ "keys": ["ctrl+shift+."], "command": "erb" },
// Paste and Indent
{ "keys": ["super+v"], "command": "paste_and_indent" },
// Vanilla Paste (no indent)
{ "keys": ["super+shift+v"], "command": "paste" },
// Reindent shortcut
{ "keys": ["super+shift+r"],  "command": "reindent" }
]

The ERB shortcut is used by SublimeERB to cycle between <%= %>, <% %>, <%- -%>, <%= -%>, <%# %>, and <% -%> and places the cursor helpfully inside of these monstrosities to ease the pain of typing embedded Ruby delimiters.

Paste and Indent makes this behavior default for ⌘-v, and allows me the option of reverting to the old paste using shift, in case I ever need it for some wacky reason.

Reindent saves me from hunting for this useful command in the menus.

Bric-a-Brac

I turn off the Minimap as it takes up valuable real estate and usually I just don’t use it.

What else? Oh yes, the app icon! The default icon that Sublime Text uses is a tad, well… it’s not nice to look at on the dock all the time. I prefer replacing it with a different one. This of course is just a cosmetic change, but there you have it. I regret nothing.

Dribbble user Lucifr offers a few crowd-sourced replacements: “Icons much less ugly than the default one for Sublime Text 2”, (they work for Sublime Text 3 too of course.)

I use this one by Daniel Matarazzo adapted from an icon by Lindsay Mindler:

Sublime Text alternate icon

To get it, follow the instructions on Daniel’s GitHub repo, although I recommend renaming the Resources folder to Resources-old or something so you can get the originals back if you need them later.

A little extra step that I found was necessary after following the above instructions was to actually replace the icon in Finder:

First download your chosen image file, preferably a PNG for scalability. Select Sublime Text.app and type ⌘-i or right-click (a useful holdover from my PC days) and select Get Info. Drag and drop your chosen image file onto the ugly icon image in the Info window (top left corner). Enjoy your sleeker Sublime Text icon.

If you have any suggestions for packages, themes or key-bindings, or if there is something horribly wrong with the above information, please feel free to reach out to me via Twitter or shoot me an email.

Thanks for reading and happy coding.

Setting Up

I recently reinstalled Mac OS X from scratch and had to reconfigure all the little tweaks that had made my development workflow easier. These were settings that I had not noticed previously since they were so ubiquitous. Now that they were gone I felt naked and powerless on my clean install.

Setting out to reconfigure my settings, it was immediately noticeable that there were quite a few special details I had forgotten about, therefore I am posting this mostly as a ‘note to self’. If anyone stumbles upon this information, then I hope they gain some inspiration to customize their development environment as they see fit. Please keep in mind these are my own preferences and your mileage may vary.

Credit goes out to Mike Busch for giving the instructions upon which most of the steps below are based. Thanks Mike!

Mike’s Environment Linter “helps identify issues with OS X machine setup for basic web development with Ruby.” After running through the steps, go ahead and check the results with it, (for example my laptop for some strange reason had both rbenv and rvm, which is not recommended. I stuck with rbenv.)

Basics

  • Mac with OS X Mavericks or later, (I am on OS X Yosemite 10.10.)
  • Sublime Text 3
  • Dropbox (to sync text editor settings between multiple machines.)
  • Terminal - Later on we can get fancier with our Terminal program, but for now the default OS X Terminal will work just fine.
  • Google Chrome with Web Developer extension. I could make an entire post just about browser extensions, but this one is most relevant to my developer toolbox.

Again, these are the just the tools I like to use, so be sure and use your own preferred browser or text editor.

Setup

Install Command Line Tools

From Terminal:

$ xcode-select --install

Configure Sublime Text from the command line, subl.

According to the docs, this command is configured to run from ~/bin directory on your home user directory, which is a bit messy for various reasons. The following alternate instructions were gleaned from this gist.

In summary, from Terminal type: echo $PATH to check if /usr/local/bin directory appears. Due to the “clean install” of OS X, either it is not in the $PATH or the folder does not actually exist. This means we have to create it first if we wish to follow the instructions from the above gist. This has occurred to me on both Yosemite and El Capitan clean installs.

If the folder does not exist, type mkdir -p /usr/local/bin from your user root directory using sudo if privilege is required. I ran into some trouble with this by accidentally entering Sublime Text 2 command and somehow creating a bin file instead of folder in /usr/local. As always with sudo and rm, it is definitely a task to do slowly and mindfully. In my case I had to explicitly cd into /usr/local to create the /bin directory using sudo, after rm the erroneous bin file. Others have reported deleting the symlink and recreating it fixed errors on this. Your Mileage May Vary.

Here is how to find the subl command location, symlink and check it(note these are for Sublime Text 3.):

$ find /Applications/Sublime\ Text.app -name subl

The preceding gives the path to subl. Use it in the next command.

$ ln -fs "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

Test in the Terminal subl -h. It should pop up some basic helpful commands. If so, you will now be able to open files and project folders in Sublime Text.

Finally, I modified my $PATH variable to prioritize /usr/local/bin: (I used the vim-like built-in bash text editor nano to be cool.)

$ sudo nano /etc/paths

(The following is a great command to alias):

$ echo $PATH | tr : '\n'

Yields:

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

So now my /usr/local/bin is first in line along the $PATH environmental variable. Later on as dotfiles start piling on, there may be more changes but for now, this is good enough to start.

Bash profile and UNIX environment

Coming from a Linux background, configuring one’s environment should be a familiar task. Luckily there is an huge source of information online if we are not sure where to begin.

Topher Lubaway has a neat group of UNIX/bash environment setup files, (also known as dotfiles,) located here. It includes some nice prompt coloring for git branch changes along with other nifty details, and I am partial to them since using them extensively. Thanks Topher!

Dotfiles are a source of pride for many developers and they are shared extensively. Check out dotfiles.github.io for more examples and tutorials. It is a tremendously helpful resource.

Follow all the instructions from Topher’s dotfiles repo including setting GitHub username and password, or just edit ~/.bash_profile and ~/.bashrc as you see fit. When choosing to use Topher’s dotfiles be aware Ruby gem awesome_print will be required when you open IRB sessions, but we can deal with that later.

Something that I like to change from Topher’s dotfiles are the Sublime Text key-bindings and preferences, but this could be a whole other future post so we won’t go into it at this time.

While we’re are at it, might as well add any alias commands we want and fancy ASCII art greetings when firing up a Terminal session. Get silly.

Run source ~/.bash_profile or exit and relaunch Terminal to confirm changes.

Homebrew

Since we have a clean install, we will need to install Homebrew. Run this command in the newly configured Terminal:

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Staying true to the craft means we need to keep our tools in tip-top shape. Update Homebrew:

$ brew update

And make sure it is happy:

$ brew doctor

Fix any error messages until “Your system is ready to brew.” appears.

Make sure that our system is using Homebrew’s installed packages.

Run this command to output our $PATH variable in a more legible format:

$ echo $PATH | tr : '\n'

And check that /usr/local/bin comes before both /usr/bin and /bin.

If we used the above dotfiles, it should. If not, open ~/.bash_profile and add: export PATH="/usr/local/bin:$PATH"

Install sqlite3 with Homebrew

$ brew install sqlite3

Force OS X to use this version of sqlite3 and not the one that comes pre-installed:

$ brew link sqlite3 --force

Install postgres with Homebrew

$ brew install postgres

Since postgres requires a server with which to interface, we use OS X’s launchd utility to keep this server running. Execute these two commands:

$ ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

If all goes well, run which postgres to confirm the location is /usr/local/bin/postgres.

We can also check that postgres server is running by entering this ps or process status command:

$ ps aux | grep postgres

Finally, create a default database and test our postgres client, psql.

$ createdb $USER

$ psql $USER

This last command opens the sql console for the default database.

Install a Ruby Manager with Homebrew

I prefer to use rbenv. There are other options, notably rvm. Choose one and stick to it.

brew install ruby-build rbenv

If we used rbenv and Topher’s dotfiles from earlier, go ahead and comment or delete out the lines of code that use rvm in ~/.bash_profile, ~/.bashrc and ~/.profile if they appear.

Install Ruby using a Ruby Manager

$ rbenv install --list

This will list all of the Rubies ruby-build can install. Choose one, likely the latest non-development build. For example:

$ rbenv install 2.2.3

And finally set the global/shell/local ruby:

$ rbenv global 2.2.3

Run:

$ which ruby

To make sure we are not using the system’s pre-installed Ruby. It should say something like this: /Users/Nyc/.rbenv/shims/ruby

$ rbenv which ruby

Restart the Terminal.

Install git with Homebrew

$ brew install git

Make sure we’re using git from Homebrew:

$ which git

Should give: /usr/local/bin/git

If we didn’t earlier, then set username, email for git.

$ git config --global user.name "John Doe"

$ git config --global user.email johndoe@example.com

Finally, set up Sublime Text as default editor for git:

$ git config --global core.editor "subl -w"

Install node with Homebrew

$ brew install node

Install Ruby gems

Make sure the load path is right.

$ which gem

Should yield, /Users/Nyc/.rbenv/shims/gem or similar.

$ rbenv which gem

Gives me: /Users/Nyc/.rbenv/versions/2.2.3/bin/gem

For good measure, update the existing gems:

$ gem update --system

Then install bundler:

$ gem install bundler

$ rbenv rehash

And:

$ gem install sqlite3 pg nokogiri

If all goes well, run both:

$ gem install awesome_print

$ gem install rspec

Restart the Terminal application.

Install bash using Homebrew

Last but not least, let’s update our most likely woefully out of date default installation of bash. See the current version running with:

$ bash --version

To install:

$ brew install bash

We need to add this version to /etc/shells.

$ sudo -s "echo /usr/local/bin/bash >> /etc/shells"

And change the shell command:

$ chsh -s /usr/local/bin/bash

Quit Terminal completely, and restart a new Terminal session. Confirm the version has been updated.

Conclusion

After this initial setup, I like to customize the text editor and use an alternate Terminal program like iTerm, OS X settings and whatnot, but I think I might save that for another post.

Something that I learned while posting this is that creating your own personal dotfiles absolutely simplifies the process of getting a development environment up and running quickly - especially if you have many workstations!

Feel free to reach out to me on Twitter or email if I missed anything. Feedback is always welcome.