18 Feb 2013

Making Marked.app Work with Vim

I found the delightful ‘Marked.app’ for OSX recently. It takes any Markdown file and parses it using a few standard Markdown interpreters, displaying a live view of the text as html.

Of course I wanted to use it everywhere. And by everywhere, I mean in Vim. And by that I mean @JEG2 posted the idea on Twitter:

Open an Emacs file in Marked.app:github.com/JEG2/dotfiles/…

— James Edward Gray II (@JEG2) January 25, 2013

And I ported it into a couple of lines in my .vimrc:

Enjoy seeing your markdown render while typing in a 30+ year old text editor =D.

18 Feb 2013

Making Thinking Rock v2.1 Work on OSX 10.8

So, PRODUCTIVITY, GTD, BUZZWORDS HERE. I’ve used ThinkingRock before when on a GTD kick a few years back. I liked how strictly it followed GTD. I liked being able to email myself thoughts to act on later, since email is the universal currency. I liked the tickle feature. I’m certainly willing to pay for software, as evidenced even by my donations to VIM, but I like the flexibility that’s available with open source software. The older version, v2.1, of ThinkingRock is available on SourceForge along with the source files. Given that I know zero Java, I thought it would be fun to have the source available for any program that I’m regularly using. So that leaves me with installing v2.1 on OSX 10.8 rather than the newer version. Unfortunately, while the newer version installs quite nicely and opens as you’d expect, v2.1 throws an error : unable to locate jdkhome, use –jdkhome switch. I Googled around and found this explanation of the JDK location and combined it with this explanation in order to come up with the following solution: hard code the bin/tr shell script to include the appropriate jdkhome location. Here’s the modified file:Note that line 21 is the modified line. Now on to revive my 3 year old GTD files, do some major deleting, get email dumps setup, and Get Things Done.

14 Feb 2013

Getting Started Configuring Bash/Zsh

I saw a post this afternoon by a member of Ruby Rogue’s Parley list asking how to write Ruby code to help them create a shorthand word for a longer commandline command. It takes moxy to ask questions on a list filled with many experienced developers. I was happy to see that positive responses flowed in. The immediate response was that the individual should perform the action by writing commandline aliases using the shell ‘alias’ command. But that only points the developer in the right direction. Instead of just pointing in the direction, the rest of this post will be walking a new developer through setting up helpful customizations in the shell environment. (Note, the generic information will be fairly compatible whether using the BASH environment or ZShell environment. Moving past general configurations into advanced configurations are where the two start to diverge, particularly with the environmental settings used in .bashrc or .zshrc files. I’ve found that the best remedy for this is reading through and gradually adopting a few lines here and there from well commented .bashrc/.zshrc files). Many of the customizations in the shell relate to minimizing repetitive keystrokes. Imagine the difference between typing

bundle exec rails server

and

be r s

If you’re typing this more than occasionally, it’s a large savings of keystrokes over a period of months. So how is it done? Aliases! Simply put, include the following code in your config file (a generic term that I’ll use for either .bashrc or .zshrc, depending on your shell): alias j="jobs" Or to help avoid dumb mistakes (it makes the remove command verbose and interactive =D. Even astute geeks fat finger the occasional keys ) alias rm="rm -iv".

I’ve taken to heart the adage, which I can’t attribute precisely, that anything typed more than a couple times on the commandline should be shortened to save future keystrokes. To prove this point, I currently have greater than 100 aliases and growing. Note that the following is from dumping all of my aliases to STDOUT via alias > jist -p -c and is not representative of one of my alias files. (For that, see the second inset codeblock).Here’s an example of one of my alias files… appropriately called ‘aliases.conf.zsh’:(Original code is at: https://github.com/zph/zph/blob/master/home/.zsh.d/aliases.conf.zsh) So that’s ‘aliases’. I find that they’re easier to keep organized if I setup a dedicated ‘.zsh.d’ folder. By which I mean that I created a folder called ‘.zsh.d’ in the base of my home directory with the following layout:

This folder contains all of the ‘zsh’ configuration files on my system other than ‘.zshrc’. Each general category of config files gets its own file, ie git.zsh, ruby.zsh, homebrew.zsh, etc. Helps me keep everything organized =D. I set the following lines in my ‘~/.zshrc’ to source each file within the ‘.zsh.d’ directory that has the extension of ‘.zsh’

_source_zshd(){
# Finally, source all the files in zsh.d (ALPHA order)
  for zshd in $(find ~/.zsh.d/*.zsh | sort );
    do source "${zshd}"
  done
}

This isn’t necessary, but it helps me keep the individual configurations nicely ordered. To recap, use aliases. Use the daylights out of them. Make your shell a finely honed tool that’s nicely crafted to your needs. Oh yeah… do the same with ‘functions’ which I can cover in a future blog post. And look into FASD because it’s awesome like Narwhals! Questions, thoughts, jeers, feedback… catch me on ‘ye ol Twitters’ @_ZPH

14 Feb 2013

Make the Shell Your $HOME

Let’s talk about how to use the shell. It’s a dirty secret that many of the repetitive commands used in the day-to-day world of developers are rudimentary shell commands.

Think of the activity of making a new folder and moving into that folder to start writing code, it looks something like this: mkdir new_project; cd new_project; vim new_project_code_file.rb.

Tighten it up and pay attention to simple improvements in the shell environment. ( My experiences are with BASH and ZSH ). That command becomes the following command with a little bit of improved shell configs: mkdircd new_project (makes dir and cds in the same command); e !!1_code_file.rb.

What’s in this shorter series of commands? Let’s break it down to parts:

  • mkdir and cd are replaced by a single new command mkdircd. We save the repetition of typing the folder name twice by compressing the command into a single request. It’s accomplished by setting up an alias in the shell configs.
  • vim new_project_code_file.rb is replaced with e !!1_code_file.rb. The e command is another shell tweak of mine. e is a shell function that steps in for the vim command and opens files for editing in a more intelligent way. See the source here: e (Note that it also depends upon the wonderful FASD utility available on Github.com).
  • !!1 becomes the first argument from the prior line, i.e. the first item after the command itself. Using !!1, !!2, !!3 has saved me countless seconds of retyping the same long folder/file names.

So, make the shell work for you! If you’re spending time in a new envionrment like the Linux Terminal or OSX’s Terminal, learn to configure that BASH or ZSH environment.

It will pay off nicely!

If you liked the article, follow me on Twitter at @_ZPH.

16 Dec 2012

Easy SSH Tunnel on OSX

I recently found myself working from a restaurant with open WIFI. After having someone on open WIFI snatch my Facebook credentials back in 2009, I’ve become understandably paranoid about security on unsafe connections. I spent a few minutes setting up a Squid Proxy on my VPS, when I came upon a better solution: set a SOCKS Proxy in OSX and create an SSH tunnel.

How it works

The SSH tunnel connects to the VPS using an encrypted channel. This is open for use on a localport such as 8080 (or a randomly assigned one w/ script). The SOCKS Proxy passes network requests to the localport instead of sending them to the web/email-server/etc.

How to do it

On OSX it consists of the two following steps: sudo networksetup -setsocksfirewallproxy Wi-Fi 127.0.0.1 $localport off ssh -f -p $remoteport -D $localport $remoteuser@$remoteproxy sleep 1d This is all well and good, but someone went to the trouble of wrapping this in a script: OSX-PROXY. I took a little bit of time this weekend and refactored the code to extract functions, utilize a case statement, and add extra commandline arguments.   My revised script also toggles the state of the proxy if no arguments are given.

Update

The aforementioned code works very well but I’m not sure if it re-routes all DNS requests which could divulge personal information. So I switched to this python library that re-routes all activity and is more established: SShuttle. Add an alias to the shell for quick starting with default settings: [code]alias sshuttle_start=’sshuttle --dns -vvr user@vps 0/0' /code. PS - Never ever trust public or semi-public Wifi.  Using a proxy like this is the minimum security that you should consider.

26 Nov 2012

Script to Update Sandy Knolls Metes and Bounds Software on OSX

After frequently finding myself not using the current version of Metes and Bounds, I wrote a Ruby script to automagically do that very thing.  It checks current version, downloads the current version, and installs it into /Applications (BEWARNED, it nukes your current version of Metes and Bounds.app, use at your own risk):Thanks to this random blog for the hint on mounting DMGs from commandline!

12 Sep 2012

OSX and Linux Tools I can't live without

I’ll keep it short and sweet but here’s the top list of tools that I’m using in various tech areas of my life.

FASD - Making me more of a speed daemon on cd’ing around terminal along with instant vimming from anywhere. PEW PEW!

Alfred - Speed daemon in graphical environment with starting new programs, running terminal commands, etc. Akin to Launchy, Gnome-Do, Quicksilver (which I wish worked better on my Mac). [This one is Mac specific but see other programs for different OSes]

iTerm2 - Customizable and nicely integrates with tmux. [Mac specific, but on Linux I’ve been super happy with Terminator]

tmux - Terminal multiplexer. Like screen, but much more easily customized. Feels like a VIM take on screen control once it’s tweaked.

VIM - My favorite editor. Mainly used in the terminal but occasionally I use MacVim for the glitz.

Vimium - Bring the powers of VIM into the Chrome Browser. Very very slick interface, especially for opening links, scrolling … just go install it.

VimRepress - Blog with Wordpress from the safety confines of VIM (as I am now)… in MARKDOWN!

GoogleCl - Commandline access to Google features such as Contacts and Calendars. Great for adding events from the commandline. Python tool IIRC.

QuickCursor - Lets me use VIM to edit just about anything. It opens a new VIM instance/buffer with the highlighted text, say from an email and pushes it back into that spot after editing w/ Vim.

BetterTouchTool - Nice easy way to assign keystrokes to open a program, move window to specific region of screen, etc. Also complemented by BetterSnapTool.

TaskWarrior - Task manager on the commandline. Like Todo.sh but with more commandline power and no Android/iOS app. Worthwhile trade at the moment after 3 weeks use. Does have a Sinatra app with TaskWarrior integration… and I’m tempted to scrape together a Ruby tool to have commandline Pomodoro tracker that integrates with Growl and TaskWarrior (as an annotate function)

And in no specific order:

-Dropbox, Evernote, DashExpander, Pomodairo, TweetDeck, Sparrow/Thunderbird (Sparrow for slick integration, Thunderbird for extensions and power), and last but certainly not least Z-Shell.

Let me know in the comments or on Twitter if I’m missing any good tools!

@_zph

19 Aug 2012

Swap out BAD line endings for Unix standard

:setlocal ff=Unix :w

Converts and saves current buffer as Unix standard line endings. n FTW!

Update

brew install dos2unix Then use dos2unix to easily swap line endings into Unix format dos2unix \*.rb

12 Aug 2012

CodeRetreat @SteelCityRuby: A Post Mortem

My head has finally stopped spinning from the CodeRetreat at this year’s Steel City Ruby Conference (2012), the fires are extinguished at work, and I’m ready to document the experience. I arrived as the first participant, not because I’m overachieving but because the Pittsburg taxi system is very irregular. I allowed the same time as the day before for a cabbie to pick me up, which was 30 minutes. Instead I was swooped up in 10 minutes and arrived nearly an hour early for the CodeRetreat at 4Mom’s office. The CodeRetreat was lead by the charismatic Corey Haines, the same bloke who set a wonderful tone on day one of @SteelCityRuby by emphasizing personal networking. In fact, the tone set by his keynote speech kept the conference largely free from individuals using their laptops during speeches! Quite a difference from other conference scenes that I’ve experienced :). But back to the point, the CodeRetreat was held in the offices of 4Moms and the food was sponsored by those fine folks. We started the day by pair programming Conway’s Game of Life using Test Driven Development. The first round lasted 45 min and we were then told that the specs had changed and to fix our code in another 10 min. Thankfully our code was relatively modular and the changes needed were minimal. We reviewed the amount of code revision needed to implement small requirement shifts and discussed how to build in flexibility and simplicity into the code.

Notes: Revelations: spending time learning social intricacies of collaborating

06 Aug 2012

Dear OSX Mail.app, go away

Dear Mail.app, I don’t want to open Mail for configuration every time an iCal notification arrives. And no I don’t want to use Mail as my default. And no, I don’t want to setup even a dummy email account in Mail. sudo chmod 000 /Applications/Mail.app PS - You too iTunes sudo chmod 000 /Applications/iTunes.app #fixing_OSX kthxbye