Companionway

Meeting challenges with success

Switched to Hugo

I am swtiching from jekyll to hugo for flat file for a Content Managment System (CMS).

alt text
goHugo.io

Here is why:

  • It comes as a binary file that runs on pretty much any platform. A single file… without a list of dependencies
  • I could stop with the last reason and it would be enough… but I have to say that the file tree used in hugo is simple, and simple is beautiful. As Einstein once said:

“Make things as simple as possible, but not simpler.”

  • It is written in googles go language… so it is fast and portable.
  • It is closely tied to git so it can easily be used on github and for version maintence.
  • it builds a clean directory [./public/] for the full site deploy and this can be rsync’d to where ever you like. or … just git push it to hithub and use something like netlify.com to host from your github!
  • No frustrating version incompatiblities (or at least very minimal) - unlike jekyll which seemed to break on me every few months.
  • hugo is relatively mature and has a huge developer backing.
  • configurable and changed without challenges
  • lots of themes to choose from
  • as the Hugo websites states - it makes the web fun again…
  • Did I mention that it is a single executable file?

Reference: gohugo.io

Enjoy -g-


Converting Images

I have fought with trying to remember the syntax for Imagemagik’s convert command for years. I finaly caved in [from my normal position of “if you can’t do it from the commandline, then you are a wimp” and sought out a gui to help me quickly convert images to use on a website. Or to just roll a picture 90 or 180 degrees. The easy solution and a standard ubuntu repository file is “converseen”.

shell/bash uppercase arguments

turning your commandline arguments into uppercase

To make a long story short… #!/bin/bash PATTERN=$(echo $1 | tr [:lower:] [:upper:]) # or PATTERN=$(echo $1 | tr [a-z] [A-Z]) # or PATTERN=$(echo $1 | awk '{print toupper($0)}') echo "Your \$1 argument is now uppercase: $1" To make a short story long… Just to let you know a little more about me and reveal a few more shells tricks along the way. I am a very conservative investor - always have been but the low interest rates over the recent past has forced me to try a squeeze a little more out of the stock market also known as a “a gentleman’s gambling parlor of greedy people”.

The GrovePi kit

Make the raspberry pi GPIO pins quick and easy to use

Check out GrovePi These kits make working with the Raspberry Pi GPIO pins so simple and clean. I just ordered one of these kits and I will try to write up a review after I work it over. If you are interested in building a quick and easy raspberry pi for experimenting with the “Internet of Things” (aka IoT) platform - this board and kit looks like it will get you there in minutes.

How to print the remainder of a line using awk

... eliminate the first X columns ...

#How to print remainder of line using awk

eliminate the first X columns…

Here is your challenge you have a list of cronjobs and you want to just execute the scheduled backup command with its arguments for a test run.

Using one command line, how would you do it?

Here is a sample root cronjob and I want to run the first entry with its arguments as a test run:

# m h  dom mon dow   command
 0 16  *   *   * /data/share/home/geoffm/dev/utils/bak-it.sh -i /usr/local/etc/include.lst -e /usr/local/etc/exclude.lst -t /data/bak/`hostname` -s 7 >/dev/null 2>&1
  5 0  *   *   * /data/share/motion/arch-files.sh >/dev/null 2>&1
*/15 *  *   *   * /data/share/home/geoffm/grab-pic.sh >/dev/null 2>&1
####### below are WIP or OLD ########
# 16 6  *   *   * /usr/sbin/lynis -c --auditor "automated" --cronjob --quiet >/dev/null 2>&1
#*/5 *  *   *   * /usr/local/bin/watch-proc.sh -f /usr/local/etc/watch-proc.conf -n geoffm@localhost >/dev/null 2>&1
#*/5 * * * * /data/share/home/geoffm/ping-pong.sh "ping -c2 192.168.1.55" "ssh 192.168.1.1 reboot" >/dev/null
#  7 * * * /usr/local/sbin/postfix_report.sh &> /dev/null

Creating that special character in vim

... digraphs to the rescue

Entering special characters into vim

I use vim as my editor. Despite this first sentence, this is not a beginning volley to an editor flame war. I will save that for another day.

Ever editor has its own unique features and vim definitely no stranger to that group. One feature I use quite a bit is what vim calls digraphs.

There are thousands of characters other than the standard keyboard character that can be displayed with vim. You may already know that you can use CTRL-v <enter> to force a linefeed into even a DOS filetype. Actually `CTRL-v ascii### will force special characters from a long list of choices.

But I prefer using CTRL-K followed by two semi-meaningful (slightly resembles the intended special character) to create any one of literally thousands of special characters.


git inside, git better, git stronger

... exploring git inside and out

… exploring git from the inside out …

###Preface

Apologies up front - this is long... very long, but there is food for the brain here. I will discuss git for personal use. Using it with many other contributors is an extension of the principle covered here. For simplicity, I am only going to discuss you working alone and only using a single "branch" of code for each project - again, for simplicity. Additionally we are going to examine the git "database" (stored as compressed SHA-1 named files/objects) as we go. We can gain a better understanding by reviewing the changes to the guts of your personal git repository. We will not cover branches, tags, or the git daemon in this discussion.

###Why git? (skip this if you are less than patient)

Many years ago I used backups of my projects or just documents, notes, etc. All worked well until it didn’t. If you make a mistake and back it up guess what,


Ansible - modifying sudoers

...avoid locking yourself out

Ansible - modifying /etc/sudoers

I have locked administrators out of using sudo with a simple typo.

With ansible you can lockup sudo on every machine with a single error. So I get pretty cautious with editing /etc/sudoers through any deployment application.

Here is a quick example of going overboard to protect your sudoers file when using ansible. This is in my $ANSIBLE_DIR/roles/common/tasks/main.yml file

- name: Copy sudoers for safety
  command: cp /etc/sudoers /etc/sudoers.tmp

- name: Create sudoers.bak
  command: cp /etc/sudoers /etc/sudoers.bak

- name: Ensure admin group is in sudoers with NOPASSWD
  lineinfile: "dest=/etc/sudoers.tmp state=present regexp='^%admin ' line='%admin ALL=(ALL) NOPASSWD: ALL' validate='visudo -cf %s'"
  register: sudoers_tmp_ok

- name: Copy sudoers.tmp to sudoers
  when: sudoers_tmp_ok|success
  command: cp /etc/sudoers.tmp /etc/sudoers

SSH basics

quick-n-dirty

SSH

Debug with verbose output

$HOME/.ssh/config first and foremost - debug with -vvvv

  • actually do it before you need to so you can see how it works

From Wikipedia (paraphrased):

Secure Shell, or SSH, is a cryptographic (encrypted) network protocol for initiating text-based shell sessions[clarification needed] on remote machines in a secure way.

In 1995, Tatu Ylönen, a researcher at Helsinki University of Technology, Finland, designed the first version of the protocol (now called SSH-1) prompted by a password-sniffing attack at his university network.


Adding fade in and down javascript

...you can make it better...

Javascript fade in and down

I wanted to change the header on the theme for my web site to display a slide down and in header.

The script needed to be a combination of two jquery animations.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('#fadeInDown')
    .css('display', "none")
    .slideDown(2000)
    .animate(
      { opacity: 1 },
      { queue: false, duration: 2300 }
      );
    });
</script>

First we load in the jquery code from google nut this a single point of failure. If there is network interruption jquery code is lost. But in my instance if the network is failing then my web site probably is too.