Companionway

Meeting challenges with success

Using a generic git pre-commit hook

test_it && commit_it || reject_it

Using a pre-commit script when committing code makes sense and fits with every respectable dev-ops model. The goal is to have respectable code before it lands in a repository. Git makes this very easy through the use of “hooks”. If you look in any of your git project directories you will find these files in the ./.git/hooks/ directory:


Vim ALE

VIM is a standard for me. My UNIX career hung on my “vi” savvy which I learned appreciate from mentors who encouraged me to learn the tips and tricks of using vi. My learning curve with vi/vim has never leveled off, but rather, always gives me new features and tricks that energize me again. The latest vim “trick” is ALE (Asynchronous Lint Engine).


Vim Scriptable Templates

Dynamic vim Templates

Vim (or vi in the anceint past) has been my partner in getting things done. Like an rich tool it has lots of features that go untapped or undiscovered. A few days ago I decided I wanted a script within a tempate to help build the “front matter” to my markdown (.md) files.

The front matter looks like this:

+++
author = ""
comments = true
date = "2018-07-15 14:45:19"
draft = false
image = ""
share = true
# slug = 
# tags = [ "tag1", "tag2" ]
title = "vim_scriptable_templates"

+++

The challenge was to have vim write in the date for me in the needed format. And if you use hugo as your static web site generator as I do you may have found that it will silently ignore a new markdown file if the date is not formated correctly. It some testing to discover that but the bottom line is that I needed a way to script it for to avoid mistakes.

Research to me to this tip source: vim embedded scripts


Hugo and Fabric

Python Fabric is a denatured version of ansible and, if you enjoy python, fabric makes a small scale devops strategy a whole lot less painful. Combined with hugo static website generator, fabic makes testing and promoting a website a whole lot easier.

I have struggled in the past with one challenge that made promoting website code from my workbench to dev, staging, and ultimately production tricky. The matter of URL always played havoc when I sent code up from one server to another for testing. Hugo offers a simple solution. When I promote website code it goes through this workflow process:


Fabric_vs_ansible

I have wrestled with ansible for too long. It is an awesome tool but you need to learn the syntax of three different languages (ansible, yaml, and maybe some python) to hold it down and control it. Every time I go to use it I have to learn how to do what I need to do. But the most frustrating aspect of ansible when learning to do something new is that your first attempt rarely succeeds - at least for me. So you resort to “force programming” to get through it. By “force programming” I mean you try this and that and then something else until it works, and I end up with a hodgepodge of debug lines commented out.


How this theme evolved

Newspaper Look and Feel

Announcing a new project: newspaper-hugo-subtheme

First credit goes to Silke V at codepen.io name “silkine” [http://www.silkevoigts.de/]. Original source code can be found here: https://codepen.io/silkine/pen/jldif

I had a coworker who had a non-profit business blog that wanted to offer a newsletter to her clients. So I got interested in finding an HTML format that gave an old traditional newspaper style and Silke offered a solution that provided a strong simple css base. Currently (2017) I find the hugo cms system to be the easiest most portable static web building application freely available. The challenge was to create a full newsletter style theme as a subtheme within an existing theme structure. So I mocked up a ported version of Silke’s newspaper css into a hugo “section”.

An example of this subtheme can be seen here: [newspaper-hugo-subtheme]

This project is a drop in offering to any existing hugo themed structure which will produce a newsletter format in an “article(s)” hugo section. A user only needs to change the title, city, and state varbiable that are stored as front matter in the ./content/articles/_index.md file. Hugo uses this file natively to discover section (in this case “articles”) specific data. All posts to the newsletter subtheme should be created in this ./content/articles/ directory as markdown files. Running hugo new articles/mynewarticle.md will create a new file with the default front matter pulled from ./archtypes/articles.md.

This project becomes a drop in addition to any hugo theme to add a newspaper type subtheme section.


MagicMirro2 and fauxmo

Warning: what follows is a cascade of issues and lessons learned… but just plain fun!

The goal

This project is designed to provide a reliable MagicMirror2 on a Raspberry Pi fitted with a 5 inch touchscreen that doubles to provide browsing if needed. This comes from a desire to have a quick aide in the kitchen that reports standard information when needed or a browser for looking up and displaying recipes etc.

The result is a raspberry pi with one wire that stands on its edge without a case and has a 5 inch display. The display can show any of the modules provided for magicmirror2 on command to Alexa or stop magicmirror on command. The rasbian desktop along with an inboard keyboard pad and touch “pen” allows you to launch a browser (or any other program) and navigate to any url. When the desktop is idle a screensaver comes up with anynumber of pleasing animations - selectable and can be rotated with screen blanking possible as well. The backlight of the screen is enough to act as a soothing nightlight. All in all, I am very pleased (and so is my wife) with the final result of this project.

There is a LOT of information here and lots of steps but it is worth it and you will definately learn lots of useful tricks. I am sure there are many improvements that could be made.

Kitchen Pi Image:1

Materials

Hardware

  • rasberry pi (in my case a model 3) with powersuppy
  • 5 inch touchscreen with plastic pen
  • USB storage (optional but recommended)
  • you will need a temporary keyboard/mouse attached to set things up.

Software

  • berryboot (which will load rasbian)
  • apache2 and php
  • magicmirror2 and various modules
  • fauxmo (from Maker Musings)
  • software for the touchscreen including touch a calibration tool
  • matchbox-keyboard
  • xcreensaver

Sorting IPs

I scan my home network frequently. There are a good number of smarthome devices, raspberry pies, phones, laptops, PCs etc. Using nmap to quickly scan a network is too slow for me - and it is a challenge to parse the output for easy reading (of course I would use awk to do that). So I use arp-scan (available in most repositories). So output might look like this:


Quick N Dirty Python Debug Function

Pdb is a great debugger for python but I like to use my own simple debug functions. Here is a simple debug function for python which could definitely be improved:


Raspberry Pi and Xrdp

I decided to have some remote desktop fun with one of my raspberry pies. Remote desktop for the raspberry pi (or any linux machine) can be done so many different ways - but the easiest from my perspective is xrdp. It is available really on any linux distro and works with Windows remote desktop protocol (kinda). It requires that you install xrdp and tightvncserver (under the covers it uses a vnc server - thightvncserver is probably the best choice here). Then as a client on my laptop I use the very good remote desktop client called remmina; again it is availalbe on almost any linux distro.