Request failed (404) ** (Mix) Package fetch failed and no cached copy available

Problem

You are trying to use hex for installing dependencies but when you are behind a proxy you get the following message:

Request failed (404)
** (Mix) Package fetch failed and no cached copy available

Solution

You can use the following to set up hex (taken from the answer here:

mix hex.config http_proxy http://proxy.mycompany.com

Error: Brunch 2+ requires node v4.0+. Upgrade node or use older brunch for old node.js: npm i -g brunch@1

Problem

Trying to start a new phoenix application while your node installation is old you get the following error:

Error: Brunch 2+ requires node v4.0+. Upgrade node or use older brunch for old node.js: npm i -g brunch@1 -g brunch@1

Solution

You will need to upgrade your node installation by following the steps below:

$> node -v
v0.10.32
$> sudo yum install nodejs npm (if npm is not available)
$> npm cache clean -f
$> npm install -g n
$> sudo /path/n/was/installed(ie /home/kosmas/bin/n) stable
$> node -v
v5.10.1

Running a specific Cop in Rubocop

Problem

You are working on an existing rails project with many rubocop warnings and you would like to fix certain types or warnings by getting only the specified files.

Solution

So for example when you use rubocop you first get the following for all the files in the project:

rubocop
799 files inspected, 17214 offenses detected

You can get a grouping of the errors by using the following:

rubocop --format offenses
7176 Style/StringLiterals
3596 Metrics/LineLength
1031 Style/VariableName
790  Style/IndentationConsistency
548  Style/SpaceAroundOperators
423  Style/Documentation
415  Style/HashSyntax
386  Style/TrailingWhiteSpace
198  Style/SpaceAfterComma
...

If you would like to know only the files for a certain type of warning to be able to fix them you could try the following:

rubocop --only Style/TrailingWhitespace
..... list of files
799 files inspected, 386 offenses detected

Using Array.wrap in Rails when the results could either be a string or an array

Problem

You want to use some array method in a value returned, which can either be a single value or an array of values.

Solution

Rails ActiveSupport Array, provides a method called wrap, that can be used to:

Wraps its argument in an array unless it is already an array (or array-like)

Full explanation of the method here.

Thanks Miles

Converting number from any base system to decimal in linux shell

Problem

You would like to quickly convert a number from a different base system (i.e. binary, octal, hexadecimal), to decimal.

Solution

Use the echo $(()) shell command to convert it passing it the current base system and the number, as in $((2#101010)) or using the O for octal or 0x for hexadecimal notations.
Examples:

echo $(( 16#FF ))
255
echo $(( 0xFF ))
255
echo $(( 8#21 ))
17
echo $(( 021 ))
17

Taken from Linux Journal’s Work the Shell column (March 2016)