24 Nov 2021

Awesome Bundler Feature: Inline Gemfiles

Ruby’s Bundler introduced a feature that I’m loving for prototypes and quick scripting

Inline Gemfiles

Introduced in v1.10, these avoid needing a separate declaration of a Gemfile and you write it directly into the script you’re creating.

It fixes the following ergonomic issues:

  • Writing a separate Gemfile when your program is a single Ruby script is overkill
  • Packaging your Gemfile to accompany aforementioned script is a hassle
  • For single file scripts you can now rely on Gems!

How To Use It

require 'bundler/inline'

# Declare Gemfile in ruby script
gemfile do
  source 'https://rubygems.org'
  gem 'mongo'
  gem 'pry'

client = Mongo::Client.new(ENV.fetch('MONGO_URL'))


I’m not writing much Ruby these days because I work leading engineers, but when I hack on things in my spare time I’m prototyping and want to iterate on an idea before converting it to Golang. I did this recently when iterating on how to speed up controlled MongoDB failovers and when spiking out a terraform-like system for MongoDB configuration management.

Bundler-inline is great for these situations because they’re a single Ruby script but require installing Gems :).

05 Jun 2014

Get rid of deprecation warning in OpenSSL::Digest::Digest

AWS-S3 complaining at you in Ruby 2.1.1?

Looks like they’re getting rid of OpenSSL::Digest::Digest and that behavior should be in OpenSSL::Digest instead.

Nix it here: aws-s3-0.6.3/lib/aws/s3/authentication.rb:71.

If I have a chance I’ll submit a PR on that (or maybe it’s fixed in a newer version).

Edit: The change is already present in the master copy of aws-s3 here

29 Apr 2013

Goals and Giving Back: Creating Meaning in Life

[caption id=“attachment_599” align=“alignleft” width=“500”] By: John O’Nolan[/caption]

I’ve been in serious discussions with a new friend regarding the refinement of the self. The discussions started at RubyMidwest but since I don’t yet have their permission, I’ll leave the individual as a shadowy anonymous figure.

The evening of the discussion brought about a conversation regarding refactoring oneself through a constant process of testing and revising.

I shared my own experience of setting actionable goals related to various facets of my life, a choice that was influence by 7 Habits of Highly Effective People. These goals run the gamut of goals, anywhere from family, friendship, business, personal knowledge, technical skill acquisition, etc. Each of the goals is categorized and provides a broadly sketched roadmap of what I want to apply my energy to during 2013.

Without going into all of the details, I’d like to provide a couple of examples.

One of my larger goals for the year is to be less of a consumer and more of a producer. This applies both in the technical world, where I want to write more code and blog entries (rather than simply consuming them) and also in my online social experience where I’m moving out of my introverted shell and making connections with likeminded individuals. Thus far, this goal has been a smashing success. I made new Ruby friends at RubyMidwest and I’m a much more active member of the online community. I’m pleasantly surprised that this is such a natural goal to work on. It has become an outlet of my energy that’s relaxing and fulfilling.

In this same vein, I’ve become increasingly interested in giving back and contributing via teaching or volunteering in order to help others along their path. Pragmatic Thinking and Learning cites the Dreyfus Model of Learning, which loosely paraphrased, indicates that because I’m a beginning intermediate programmer, I’m uniquely prepared to lend a hand to beginners. The fact that I’ve been teaching myself Ruby for the past 3 years means that beginners' struggles are fresh in my mind. So I’m taking what time I can out of my schedule to lend a hand to the next generation of passionate programmers.

Perhaps in the not too distant future, I’ll have a work setup that encourages and allows me to spend a portion of my time giving back to the community. The time’s approaching where I won’t be able to resist the allure of professionally joining the ranks of software developers.

If I may breach the fourth wall, what are your goals and aspirations gentle reader? I’d love to hear about them in the comments or in the walled garden of Twitter @_ZPH.

PS - Start mentoring someone, now!

12 Apr 2013

RubyMidwest 2013: Lessons and Reflections

20130411 RubyMidwest 2013 Me, Evan Light and PJ HagertyI attended RubyMidwest and want to share both my impressions and resulting growth. But let’s backup, I had debated whether to drive or to fly out to Kansas City, MO for the conference. With only two weeks to spare, our primary long distance car began having some trouble. So, I looked into the costs of renting a car, the cost of wear and tear on our car, vs the possibility of flying. After tallying up the costs and figuring that I could work part of the day while flying, I booked a ticket for Kansas City. In the future I’ll be more eager to travel by air, given that I can successfully work from anywhere with WiFi or 4G Coverage. To a lesser extent, for non-connected work, I’m also productive without the internet. If my first successful choice was flying, then my second successful choice was when I scheduled my arrival and departure. I flew in the day before the conference and out the day after. By doing this, I was rested going into the conference and able to socialize the night before it started. Flying out the day after the conference had the same effect of enabling more time with the folks that I wanted to see. Now mind you, I find these concepts fairly un-engaging but they’re important for getting the most out of the conference experience. My next big win was staying at the official conference hotel. This means that at 4am when you can barely see straight from tiredness, your bedroom is only an elevator away. Staying at the main hotel also encourages social activity… which is why we’re really at the conference. Yes, it’s more expensive. Yes, it might be a tacky venue. Yes, it’s not all magically hipster delicious. If money’s an issue, post on Twitter that you’re looking to split a room. I had the pleasure of sharing the room with Evan Light because he posted on Twitter about the hotel not having vacancies. Sharing a room’s also a great way to make sure you’re staying in the social mix of the conference rather than scuttling off to a quiet place.

Twitter is the lifeblood of Ruby Conferences.

Add a column in your Twitter client to track the hashtag designated by the conference. This means you can follow the flow and group activities. It’s also a good place to share your enthusiasm for RubyMidwest and ensure that next year has an equally awesome crowd. If you’re shy or want help being social, post something like, “Hey come say hi to me, I’m wearing a Yellow Gnu Linux T-Shirt”. Incidentally, that’s how I met Matthias who is writing this book about the Padrino Framework.

Never Eat Alone

Except for coffee when you’ve just rolled out of bed after 4 hours of sleep. Otherwise, don’t eat alone. This is your magical chance to spend time with people as nerdy or nerdier than you. If you’re stumped for conversation, ask how they started programming, what their favorite Gems are, what tools they use, if they’re part of the 20% of programmers who Raided in World of Warcraft (then judge them according to whether they rolled Horde or Alliance).

Find a Small Group

I preferred the time spent in groups of 2-8 people. This size allows for meaningful conversation between the participants. It’s also easier for those of us who are slightly hard of hearing. Each night of the conference had some conversational highlights. Friday night’s highlights were centered around the balcony at the after-party. @kobier, @elight, @samullen explained to a fellow not from the conference what it was that programmers do. By the end of the conversation, the young man was very enthusiastic about learning to program. I volunteered to help him get started and we’ve been in email contact since the conference ended. This conversation was an impressive display of the welcoming attitude that can exist in the Ruby community. On the last night of the conference, after the energy had worn off, I had some meaningful and insightful conversations. I’m looking at y’all: @Bantik, @zmoazeni, @aspleenic, @ashedryden, @erniemiller, @kerrizor, @theOtherZach, … and more.

Initiate Conversations

I started many conversations at RubyMidwest simply by walking up to people and introducing myself. The odds are that this will lead into a flowing conversation. If it’s stilted and awkward, get the conversation onto technical topics… that’s the bread and butter of conferences. Also, people at regional Ruby Conferences are remarkably friendly.

Company Culture Shows Through Employee Behavior

I’m looking at you genial folks from @Harvest: Zach and Paul. Sending folks who positively represent your company to community conferences is a win-win situation. The devs get to stretch their knowledge and have fun. The company builds a reputation among Ruby’s enthusiastic true believers. Why wouldn’t companies want to recruit from this pool of people?

What Did I Really Learn?

That I’m attending MadisonRuby, SteelCityRuby and DCamp this year. I finally decided to transition from an anonymous icon on Twitter to a goofy pic of myself.  Doing this is a direct result of making #rubyfriends at the conference.  And when they see me on Twitter, I’d rather that they see my face delivering the pithy witticisms. I’ve submitted a conference talk proposal to two venues since returning from RubyMidwest.  I’m also excited about stepping up my programming game and getting more involved in the community. These are my people :).


To Wes Garrison of Databasically, Sam Mullen, Ross, Cerner, and everyone who made this event possible.

18 Feb 2013

Executing Ruby from Vim

Want to run a Ruby script in Vim? Maybe you’re testing a little commandline snippet. Maybe you want to run a quick query against a webpage. Maybe it’s none of my business why you want to run the Ruby script!

Well here’s a little selection of my Vimscript that accomplishes just that:

Typing your leader key (mapped to '' by default but remapped to ‘,’ by you, right? ) and hitting ‘rr’ in quick sequence will execute the current file using your Ruby interpreter. If you’re using RVM to manage your Rubies, you might also want to consider adding the vim-rvm extension to use the ‘correct’ Ruby.

18 Feb 2013

Toggling Pry in Ruby Script

I’ve been using the daylights out of Pry ever since learning about it ~ 1 year ago. I’ve also been evangelizing about it to anyone who will listen:

@_zph Thanks for reading!And thanks for teaching me tmux and pry.Been trying them here and there - still very shaky with tmux.

— Steve Jackson (@stevejxsn) February 16, 2013

The most recent way that I’m using Pry is by dropping the following line into anywhere that I need to work with:require 'pry'; binding.pry

But adding that to scripts and then deleting it becomes repetitive. So here’s a little Vim function that that toggles my Pry statement. If the current line matches the Pry snipped, the line’s deleted. If the current line doesn’t match the snippet, then the snippet is added at the cursor. ( It’s best used on a blank line until I make the function more robust. )

Special thanks go to @Banisterfiend for all his hard work on the Pry gem. It makes my Ruby life a much happier experience. If you’ve benefited from his hard work, please consider a donation @ the following link.

Also, special thanks to Tim Pope. Reading his vim-fugitive code gave me the syntax hint on how to make this work.

17 Feb 2013

The Value of Experienced Developers

I had the pleasure of talking today via Twitter and Skype with Wes Garrison, Founder of Databasically, one of the organizers of Ruby Midwest and all around nice guy. We met back at SteelCityRubyConf during the CodeRetreat and have been in intermittent Twitter contact since.

We talked about a project that I’m finalizing in order to pitch to my company. His feedback on the app, especially in pointing me directly to a solution for highlighting, reminded me that I need to spend more time with experienced developers. In those few minutes he pointed me to the tools that increased the value and utility of my product. Within minutes of getting off of Skype, I added the highlighting feature, tweaked the CSS, and a bit of the underlying Ruby. It’s a big improvement :).

After the Skype conversation ended, the conversation continued on Twitter with Wes pointing out that I should consider using the Decorator pattern in my Rails application. I remembered seeing Draper on Github and an hour later I had a working implementation that abstracted away some complexity from my views. Yet another point related to him having more experience than I.

I’m reminded how much easier it is to learn from people who have already walked a certain path and distilled the necessary knowledge, rather than re-inventing the wheel yourself. This isn’t to say that developers should rely on others for all their answers, but I’ve been 100% self sufficient with my trusty Google-based answers thus far. It’s time for me to better network and share knowledge.

To this end, I need to make time for remote pair programming. I met @JoelByler of LeanDog at a CodeRetreat in Cleveland earlier this year. We discussed remote pair programming for fun, but with household responsibilities, preparing a product to pitch, and longer than normal work hours it’s been tough to schedule.

But tough to schedule is no excuse. I’m getting more diligent about reducing my time consuming blog posts and external information and making a dedicated goal of increasing my productivity. Not hoaky productivity like you see blogged about on Lifehacker.com where you read about a million ways to improve productivity while accomplishing nothing in life. I’m talking serious productivity of cutting out unnecessary fluff time, idle web browsing, and conserving effort for producing things. Some of my current goals in this regard are another couple of web applications related to my industry, a series of webcasts, building a newsletter list of people interested in the theme of the screencasts and providing that set of readers with tailored articles. I’ll have a much easier time of this if my employer sees the value in the product I created and transitions me into a development role. That way the web apps can be developed during work time :) where they will also be consumed by my fellow teammates.

In closing, I’m working on things that I can control and appreciating good advice when I get it.

If you’re reading this in the Kansas City area and need help with tech stuff, Wes Garrison @ Databasically will solve your problems. Give him a ring.

If you’re in the Cleveland area or just want a good group of people to work with for your Rails application, get a hold of LeanDog. Joel Byler, Steve Jackson and the rest of the crew are a good group of folks.

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


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’

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

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

29 Dec 2012

Trello-Archiver from Scratch

Trello-Archiver is a set of Ruby scripts that allows one to export their Trello board into a CSV, TSV, or XLSX file. It was started by another person on Github.com named Mad_Typist. Early on in the process I sent them a pull request to contribute my changes back… but they don’t seem to be around. Given that, I’ve forked the project and continued to develop it for my own benefit.

Trello-Archiver relies on a few conventions that exist in the Ruby world. 1. Project dependencies are managed with Bundler 2. A semi-recent version of Ruby is used >= 1.9.2

To use the project on a system that isn’t setup for Ruby development, the first step is to install a recent version of Ruby. I prefer to use a tool called Ruby Version Manager for this RVM.

Install a sane Ruby Version Manager along with Recent Rubycurl -L https://get.rvm.io | bash -s stable --ruby

Source the installed script to allow for using RVM this first time w/ this command: source ~/.rvm/scripts/rvm

Future logins will automatically source RVM using your bashrc or zshrc.

The next step is to clone the Trello-Archiver repo from Github.

Then cd trello-archiver and run bundle install. Bundler installs the necessary dependencies for Trello-Archiver. The nice feature about Bundler is that it manages individual projects' dependencies independently :).

Next, cp config.example.yml config.yml. Config.example.yml is the template for where the authentication credentials are stored along with any default settings.

Open up config.yml with your favorite text editor. Instructions are inclosed in there for how to gather your secret credentials from Trello.com.

First, open https://trello.com/1/appKey/generate in your web browser. Copy the first key as your ‘public key’ and the second (longer) key as your ‘private_key’.

Next we need to enter those values into a special url: https://trello.com/1/connect?key=PUBLIC_KEY_FROM_ABOVE&name=ANYNAME&response_type=token&scope=read,account&expiration=never The two values that need replacing in this URL are PUBLIC_KEY_FROM_ABOVE nd ANYNAME. ANYNAME is a placeholder for any text that you want to use to identify this key, ie it could be TrelloArchiver. Also note that this is authorizing Read-Only access. This way, even if there’s a bug in the software the token won’t allow changes to your Trello information.

Past that value into your web browser and click allow on the confirmation webpage.

The following page that loads has your ‘access_token_key’. Copy this value into your config.yml. Save config.yml and exit to commandline.

That’s it for authentication setup! Make sure to be careful with this config.yml and don’t go adding it to any public git repos ;).

Now for backing things up :). Decide if you want a specific board backed up or all of them.

Let’s backup a single board: -ruby bin/trello_backup.rb -Choose your board by number and hit enter -Enter a filename or not (it defaults to name of board and date stamp) -Defaults to exporting as XLSX (this is easily changed in script).

Now let’s backup all the boards: -ruby bin/trello-autoarchive.rb -Sit back and wait for it to finish! -It’s set to backup all boards with default names and using XLSX filetype.

Caveats: It saves these files into the current folder. Apparently I broke CSV functionality with some recent changes. I’ll get it working again. The spreadsheet structure is what works for me. If you need a different configuration, please let me know and I’ll look into it. Not all info is backed up. For full backup, download your JSON export from Trello. The main thing that I didn’t include in Trello-Archiver is a set of timestamps for when a Card is moved to each List. This could be a future feature if others have a need for it.

Below is a Gist showing the shell commands

24 Dec 2012

Ruby Off The Rails - Ep. 1 -- Zero to Ruby -- Pt. 2

Here’s the second installment, briefly covering installing RVM and an approachable text editor (Sublime Text 2). I advocate for focusing learning on one area at a time which means learn Ruby rather than starting to learn Ruby and VIM at the same time. (Learn VIM or EMACS once you’re further along with the language itself and see it as a long term investment in your productivity and happiness as a code crafter). Ep. 2 – Zero to Ruby – Pt. 2 Ruby Off the Rails - Ep 2. - Zero to Ruby Pt. 2 from ZPH on Vimeo. Here’s the source for the commands used in the episode: