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.
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.
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>.
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!
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.
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.
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.