Friday, September 04, 2015

NPM without sudo


In development environments, access to install NPM global packages under the standard /usr path if often restricted. Instead of using sudo for global package installation, which is rarely the desired solution in development, it is possible to instruct NPM to use a directory owned by the logon user as follows:

mkdir ~/npm
npm config set prefix ~/npm

After this, installing a package globally, such as:

npm install -g async

will result int the library files being placed under the configured location (~/npm in this example).

Tuesday, September 01, 2015

Awk: generate random sentences


cat /usr/share/dict/words | 
  grep -v "'" | 
  shuf | 
  awk -v wordCount=100 -v wordsPerSentence=5 '
    BEGIN {i=0} 
    (NR<wordCount) {
      if (i<wordsPerSentence) {
        a[i]=$0; 
        i++
      } else {
        for (j=0;j<length(a);j++) {
          printf ("%s ",a[j])
      }
      print
      i=0
    }
  }'