bckfile—backup a file with sequential numbering

I have discovered over the years that protecting a file, its content, and developing in a controlled, deliberate method is usually something good to keep in mind. I have learned that if I feel an document, project… is important, then to backup the data and then do the edit is the methodology I need to learn.

When I decide to backup a file, first thing I do is to see if there is a _vault directory. In any location where I had to backup previously, I created this directory. After the first time I did this I realized I was going to have to number these file backups. I reasoned out that filename_[0-9][0-9] would be a format that would be sufficient, if there was an extension it would be filename_[0-9][0-9].ext.

As I could see that file backups were something that I would regularly do, I decided to create a script that would automate this task. It tests the destination directory if the file exists. For the first backup, the script prepends 00 to the file, after that its prepend the sequential number.

The usage is basic: I define the source file and optionally the destination directory. The current directory is assumed if only the source file is specified.

An example:

$ bckfile file.txt _vault
‘file.txt’ -> ‘_vault/file_01.txt’

The script does have one limitation: the filename can only contain one period and it must be for the extension. This is necessary as determination for an otherwise intention would take a lot of work 😊.

bckfile can be found in my general scripts repository.

gt—create a gedit scratchpad

geditmp—a-script-to-create-a-gedit-scratchpad

I am really lazy with my editors. I have aliases in my shell configuration for gedit and vim to open them as quickly as possible:

alias v="vim -p"
alias sv="sudo vim -p"
alias g="bgcmd gedit"
alias sg="bgcmd gksudo geany"

This is very nice for me because I use my editors quite a bit. One thing I needed though was a command that would create and open a temporary file in gedit. The main reason for this is that, there are times, I don’t know how to name or place the file properly yet. At other times, the reason is, I like to have a scratchpad that would save information that I might forget if it was just a new file and I forgot about it or a crash happened.

The bash script

Running gt will create and open a file named with the current time (MMDDhhmm) and will be saved in the trash folder. If gt is followed by a name (e.g. gt geditmp.md) the name will be appended to the time.

geditmp-example

The name is helpful if wanting to dig the file out of the trash folder at a later time.

#!/usr/bin/bash
# (g)edit (t)emp. file — create gedit scratchpad

tmp_dir=~/.local/share/Trash/files
tme_day=$(date +%m%d%H%M)

[ ! -d "$tmp_dir" ] && mkdir -pv "$tmp_dir"

# gedit existence test
hash gedit 2>&- || { echo "Requires program \"gedit\"."; exit 1; }

# Usage
if [ "$1" = -h -o "$1" = --help ]; then
  echo "${0##*/} [name1] [name2*] — create a gedit scratchpad"
  exit 2
fi

if [ "$1" ]; then
  for name in "$@"; do
    nohup gedit "$tmp_dir"/"$tme_day"-"$name" &> /dev/null &
  done
else
  nohup gedit "$tmp_dir"/"$tme_day" &> /dev/null &
fi

Write The Fine Manual with pod2man

Disclaimer: This is a guide for basic manual writing. It uses a simple markup language and converter to create a manual. It is good for beginners. For a good general overview of man pages read this, for more common approaches to writing manuals read this post.

An example

To get a good idea of how to write a manual seeing the markup of a POD (Perl’s Plain Old Document) works well. This is a POD for a fictitious program called dr-smile:


=encoding UTF8

=head1 NAME

dr-smile — output platitudes to help to improve one's mood

=head1 SYNOPSIS

dr-smile [B<--happy>] [B<--joke>=F<type>]

=head1 DESCRIPTION

B<dr-smile> outputs jokes and happy thoughts designed to make one feel F<--better>. It has the ability to output pleasant thoughts, jokes, good memories, optimistic fortunes, or just give you a big hub. B<dr-smile> is for I<entertainment> and for light mood change requirements. Please use responsibly and with greater change requirements please see an appropriate professional. Additional options are available in the configuration file F</etc/dr-smile.conf>.

=over 4

=item B<-h>B<--happy>

A general happy thought will be output (e.g. C<dr-smile --happy>).

=item B<-j> F<type>B<--joke>=F<type>

A good-sense joke will be told.  The types are: F<knock> and F<oddball>.  Read more in B<jokes(1)>.

=back

Text formatting

Man pages are mainly created with these types of formatting:

Format Markup
bold B<text>
italic I<text>
link L<http://address.domain >
file name F<file-name>
email E<name@address.domain>

Note: E<> is technically for escapes, however, I have seen it used before in another pod2man document—whether intentional or not I am not sure. Read the manual perlpod for markup information.

From a general observation over the years, bold and italic formatting get used in these situations:

Bold:

  • program names
  • options
  • other manuals

Italic:

  • keywords
  • emphasis
  • arguments
  • occasionally manuals

Category formatting

Manual page categories are generally formatted with a certain order. The order of categories vary a bit per man page but the first four are usually present. Here is the general structure and their purpose

NAME
  The name of the command followed by a one-line description of what it does.
SYNOPSIS
  A command's invocation with its listed options, or a functions parameter listings with its header file.
DESCRIPTION
  An in-depth explanation of the command or function.
OPTIONS
  A explanation(s) of what an option does these are sometimes put in the DESCRIPTION.
EXAMPLES
  Some examples of common usage.
FILES
  Files related to the command or function.
BUGS
  List of known bugs.
SEE ALSO
  A list of referenced or related commands.
AUTHOR, HISTORY, COPYRIGHT, LICENSE
  Information about the author...

For how to create the categorical entries, I only know the basic formatting. Look at the above example to see how it is done.

  • Category begin is defined with the head1 tag.
  • Indenting is done with the over 4 tag.\
  • Category item is defined with the =item tag.
  • Category end to define a new category is done with the =back tag.

Document to manual conversion

pod2man usage is basic. First look at manual section definitions here to know what section it should belong to. For my miscellaneous, fictitious program:

pod2man dr-smile.pod > dr-smile.7

Additional information may be wanted to add to the manual along with compression:

pod2man --section=7 --center="General Commands Manual" --release="1.0" \
dr-smile.pod | gzip > dr-smile.7.gz

To view the man page use man -l dr-smile.7.gz.

screenshot-manpage

Resources

xuserrun—run a command as the currently active X.org server user

xuserrun is a bash script to detect the first X.org server environmental values, these values are then used to transmit a command to it. The script is primarily useful from another environment: a different user, from the tty console, from cron, a boot script…. xuserrun requires systemd.

Running it is basic:

xuserrun xclock -digital

Another example:

xuserrun notify-send "Remember to get bread."

I have put it in its own repository.

Audio file encode to a video file

I wanted to convert an MP3 file to a video file to be able to use it on my PS3. The PS3 has an audio player but it doesn’t remember the position. It was an audiobook so it was best for me to convert it to a video file.

#!/usr/bin/bash
# Create video file from audio file.

# Required programs.
if ! hash ffmpeg 2>&- ; then
  echo "Requires program: ffmpeg"; exit 1; fi

# Usage.
if [ $# != 2 ] ; then
    echo "${0##*/} <image> <audio> - create video file from an audio file."
    exit 1; fi

# Files existent test.
if [ ! -f "$1" ] ; then
    echo "non-existent image: "$1""
    exit 1; fi
if [ ! -f "$2" ] ; then
    echo "non-existant audio: "$2""
    exit 1; fi

vid_nme="${2%.*}".mp4
ffmpeg -f image2 -loop 1 -i "$1" -i "$2" -c:v libx264 -tune stillimage 
  -c:a copy -strict experimental -shortest "$vid_nme"

#ffmpeg -f image2 -loop 1 -i "$1" -i "$2" -c:v libx264 -tune stillimage 
#  -c:a aac -strict experimental -b:a 192k -shortest "$3".mp4

Handling display calibration

Though it is the expectation that a monitor is ready as soon as it is removed from the box, most monitors need to be calibrated. A much more vivid, detailed, true experience can become available after it is done that can be enjoyed and “feels right”. Calibrating a monitor correctly requires training of the eye so it initially can take a bit of work.

Hardware

All settings done to calibrate the monitor should be done on a hardware level (except for possibly gamma) as software solutions almost never adjust the image truely. Before beginning, have the monitor on for about ten minutes as it can take the lamp this long to warm up and represent accurate values.

Gamma

Gamma correction is the adjustment of mid-tone luminosity. It is used to compensate for the non-linear relationship between the input signal and the luminance of a monitor. Televisions, computers, and the internet use a gamma of 2.2 as a standard so monitors set to this to be able to correctly display output. Most monitors default to the 2.2 standard but some monitors deviate and therefore hardware and/or software gamma correction is required. A high gamma will look glowy and a low gamma will appear errie and dark.

Alternate

Gamma test and Alternate

There is likely a gamma setting on the monitor if it needs to be adjusted. If there isn’t, or for further adjustment, a software solution is available. The first software solution would be to use the EDID data built-in to the monitor of most modern-day computers. It contains details about the monitor including gamma correction. The Desktop Environment may have the ability to grab the EDID and save it as an ICC profile (GNOME does), otherwise a program like Quickgamma in windows will do. If the monitor does not have EDID information, Quickgamma also has the ability to manually-calibrate the gamma and create an ICC profile from that; it saves the ICC profiles to C:\Windows\System32\spool\drivers\color.

To load an ICC profile put it in ~/.local/share/icc/ and see if your Desktop Environment supports it. If it does not, a good program that can load them is xcalib.

In the image, lightly squint the eyes (or step away) to find the match where gamma blends with the background.

Contrast

Contrast defines the tonality of an image. Tonality is the gradient leveling from light to dark. With a high contrast the light and dark extremes become “crushed” or “blended” together, a low contrast the and images will appear flat. Contrast is also reflects the white-level (the brightness of white) of the monitor; contrast levels are often defined when buying a monitor because they will tell how bright the lamp is.

In this image, turn up the contrast to maximum and the reduce until all whites become distinct and the first block is just barely discernable.

Brightness

Brightness is better-referred to as black-level as it defines the “brightness of black”, or how bright darkness goes. Black is “black” or will be just above the black of the monitor if turned off. Adjust the image so that the left box just barely discernable. It may be necessary to go back and forth between contrast and brightness until the right balance is met.

Note: Discernability of the lightest light boxes and the blackest dark boxes should be possible on a modern monitor; however, it should be known that some monitors are unable to reproduce them.

Color balance

For color the first thing to do is adjust saturation. Saturation is the total amount of color the monitor will display. Too much saturation and images will be heavy with color, too little and they will appear faded. On some monitors the setting will be called Color, on others it will be Saturation, and on others it will be controled through an accumulative adjustment of the Red, Green, and Blue channels. Use the images below to determine saturation. Skin tone is a good indicator for this; however, also look at the colors on the color wheel as “bleeding” will at times occur when over-saturation occurs.

To adjust the color balance, also use the images below with skin tone as a reference. Do one color at a time, go back and forth, back and forth, until it feels right. When doing this be careful not to strain the eye too much as eye fatigue effects colorreception. Take a break after a little bit (get up and strech, make lunch…) and come back and you’ll immediately see, “Ah, the image is too red” or “Ah, the image is too blue”… The base colors Red, Green, and Blue also have complementary colors or complmentary light, the opposite of Red is Cyan, Green Magenta, and Blue is Yellow. If an image has too much Magenta it will need more Green. Again look at the skin tone (the gray in the first image works good). This is where the trained eye comes in. With practive eventually color bents will become discernable. Once it is achieved, the discovery of a well defined monitor can be begun to be enjoyed.

Skin-tone, gray background

Skin-tone, gray background

Light skin-tone

Light skin-tone

Darker skin-tone

Darker skin-tone

Resources

Architectural Intent – a Wallpaper Tile



I tend to use my desktop as my workspace so I like wallpapers that act as more of a background decoration rather than elaborate artwork. So I created this. This is based on a wallpaper I found on the net (sorry, can’t remember where) and I re-did it. The original was in jpeg format and it had a bit of dithering to it.

It’s real basic, just 140×140, but I tile it and it comes out real nice:

It’s a vector image so it’s able to be resized real easy if need be.