Don't Deal With Ambiguous Data

Mutate Ruby Objects or Don't. Never combine the two.

Andy Huynh

1 minute read

Everytime an object or variable is invoked by a non mutating action, the object remains untouched. This is particularly relevant when passing objects around via method calls. If the passed hash gets mutated along the chain, receiving class method require more responsibility to handle ambiguous data. New hash keys could be introduced or removed which changes your expectation of what you’re getting. This is cautionary coding we want to avoid. Seldom is the case to mutate objects holding state or data.

Stack Level Too Deep - Not Too Deep For Me

Guard against Double Loading when Monkeypatching with Alias Methods

Andy Huynh

2 minute read

Before we discuss how to guard against a double load when monkeypatching with an alias method, know that a stack-level-too-deep error is a good indicator your method has already been defined. It loaded already and is trying to load again. This is commonplace in background jobs where a class might get loaded more than once. It’s unfortunate for your monkeypatched method being called because you’ll go through an infinite loop which leads to the error above.

Customize Your Vim Setup; Thank Me Later

Create a Leader Command for Vim Paste Mode

Andy Huynh

1 minute read

Ever copy something to your clipboard to NOT have it appear as you would expect in Vim? Pasting from another application to Vim yields wonky results because Vim doesn’t know how to handle the clipboard’s content. Vim has a paste mode you can toggle on or off using :set paste and :set nopaste. Vim has a one liner you can add to vimrc to transform into a Vim paste toggle: set pastetoggle=<F2>.

Typo All You Want with Vim

Just a trick for more accurate spelling with Vim

Andy Huynh

1 minute read

I like to code recklessly. Spelling errors aren’t uncommon when this happens. Defining variables and calling them in different places where I expect them to work and they DON’T work is a problem. There’s a command with Vim that’s handy for this situation. Hover your Vim cursor over the variable you instantiate and SHIFT * over it. This will highlight each variable with the same variable name, one by one. It allows you to visually see each variable and if it’s defined with accurate spelling or if you fucked up!

Use Git To Debug Your Problems

Git Stash and Diff as Experimental Tools

Andy Huynh

2 minute read

A common scenario working on a new feature is to recklessly code and pray it all works. Often times, this MIGHT work. Sometimes, shit hit the fan. Here’s a Vim/Tmux/Git trick to view changes and incrementally add code to debug your problems.. all on a single screen. 1. Open three panes in Tmux: Vim and two terminal shells. You’ll want a pane to edit code, another to see diffs and the other to run a stash.

WTF are Affiliate Links?

Tutorial - Create Affiliate Links for User Accounts

Andy Huynh

2 minute read

Your SaaS project is taking off and you’re making $$. Customers want to sell your product. Let’s utilize Rails to create affiliate links so customer accounts will sell for you. We’ll want to generate an affiliate link akin to: https://<your_hostname>/r/<affiliate_token> This is made up of a protocol, your hostname and affiliate token - in that order. Rails url helpers will pick up current request protocol and hostname for us. This will make life easier.

Your SHA is Your Friend

Save your Latest SHA when Rebasing to Master

Andy Huynh

1 minute read

You’ll want to do yourself a favor before making major rebases from master to your feature branch. Save your latest SHA Jot down the sha of your latest commit. This has saved my ass several times. You’ll avoid sifting through the dreaded reflog trying to figure out where you fucked up. Execute a git log and copy the SHA to your notes. Use git reset –hard <your_sha> to go back to that state.