Author Archives: Todd Partridge (Gently)

gurl – a curl general download wrapper

Because I don’t need another download program (and sometimes I find it not installed) I built this:


#!/usr/bin/bash
# A curl general download wrapper
# -l : redirect automatically
# -O : output filename is remote name
# -# : progress bar
# -w : (--write-out) print filename
# -A : user agent
#    : resume difficult (wget -c, better): http://tinyurl.com/7umwyl3

for u in "$@"do
  curl -l -O -# -w "%{filename_effective}\n" -A "Mozilla/4.0" "$u"
done

And it looks like this:

# gurl http://.../archlinux-2014.09.03-dual.iso
###############################                                           43.4%

Vim colorscheme tuneup

I hadn’t thought about it for awhile but today I updated by Vim colorscheme for the first time in about two years. In the process I found a few that were notable:

rdark-terminal

vcs_1_rdark-terminal

link

gruvbox

vimcs_2_gruvbox

link

synic

vcs_4_synic

I think this one is based on neon. link

kolor

vcs_5_kolor

link

jellybeans blueberry

vcs_7_jellybean-blueberry

This is what I decided on. It’s jellybeans with a twist. I put this in my ~/.vimrc for the adjustments:

colorscheme jellybeans
" Jellybeans colorscheme edits (not working)
"let g:jellybeans_overrides = {
"\   'Normal': { 'ctermbg': '242' }, 
"\   'CursorLine': { 'ctermbg': '238' },
"\}
highlight Normal     ctermbg=323232
highlight Normal     ctermbg=303030
highlight CursorLine ctermbg=238
highlight Visual     ctermbg=240

Others may have different results though as the theme alters dynamically as per background (mine is #323232 btw).

Download

I got these from a collection today and have put them in the AUR

Lg monitor ips224v-pn, look

I decided to get the LS IPS224V-PN and here is a look at it. First thing I noticed was that the stand was a bit… rickety, probably from the thin neck. This does get noticed especially with the desktop I own, tetters. The second thing I noticed was how even the picture was: good, crisp, even, vibrant. The other thing I noticed was the permeating, yellow din that I’m familiar with with LEDs. This last thing can fortunately be adjusted).

Details Value
Contrast ratio 5,000,000:1
Resolution 1920×1080
Response time 14ms
Input D-Sub, DVI, HDMI
Output Headphone
IPS Yes

I’m not sure what ips is but I think it contributes to the nice viewing angle.

Setup was real easy, took no more than a few minutes and monitor calibration was basic.

Setting Default New
Brightness 100
Contrast 50 71
Color Temp Custom Cool

The color temperature of cool does a good job to neutralize the yellow color the LED; however the custom setting did better with pictures.

Alternate (yellow LED color remains):

Setting Default Alt.
Brightness 100
Contrast 50 67
Color Temp Custom
Red 50 46
Green 50 46
Blue 50 59

Ultimately I choose to use the cool temperature.

The power button is a large half-circle with an refracting light to indicate power-saving. However, it is extremely bright. There is an option to turn it off when the power is off, but it will still be seen in standby-mode; I’ve had to cover mine up.

I got this display for reading and it is good for that. Text looks very nice. But it also is good with pictures at least as far as my semi-professional eye is concerned. The 14ms (WTG?) response time is a bit on the high end. Videos do show a bit of “ghosting” but it doesn’t bother me that bad.

File backups with sequential numbering

I’ve discovered over the years that sometimes I shouldn’t just dive in and edit a file. That, sometimes, I have grand ideas that aren’t so super. I’ve made edits to files, quit and saved them, then ran them as a script, or read them as a document and said, “Oh boy”. So basically, now, I approach editing files cautiously and if I have any doubt they can be flubbed, then first I will do a backup.

When it is the point where I know a file has to be backed up, first thing I do is check and see if there is a _vault directory. In any location where I had to backup a file previously, I created a _vault directory. After the first time I did this I realized that I was going to have to number these file backups. I reasoned that filename_[0-9][0-9] would be an reasonable format. If an extension was there the entire format would be filename_[0-9][0-9].ext.

As this is something I regularly do, I decided to build a script to make this a bit easier. The usage is basic — I define the file and optionally the destination-directory. If the destination directory remains unspecified then the current directory is used. An example:

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

The limitation of the script is that files can only contain a period if used for the extension. This is a all but necessary as there would be no easy way to determine in a script if a period in a filename is for an extension or actually a part of the filename.

bckfile can be installed for Arch Linux users as part of the AUR package of my general utility scripts: genscripts-git.

gt — a script to 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 but would rather not lose information if it was just a New File and I forgot about it, or a crash happened.

The bash script

Running geditmp will create and open a file named of the current time (MMDDhhmm) and will be saved in the trash folder. If geditmp is followed by a name (e.g. gt geditmp.md) the name will be appended to the current 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/open a temporary file(s).

# Variables
tmp_dir=~/.local/share/Trash/files; [ ! -d "$tmp_dir" ] && mkdir -pv "$tmp_dir"
time="$(date +%m%d%H%M)"

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

# Help
if [ $# -lt 1 ] || [ "$1" = -h -o "$1" = --help ]; then
  echo "${0##*/} [name1] [name2*]… — gedit temp. file. Create/open a temporary file(s)."
  exit 1
fi

for name in "$@"; do
  nohup gedit "$tmp_dir"/"$time"-"$name" &> /dev/null &
done

WTFM (Write the Fine Manual) with Pod2man text-converter

Note: This is a guide from a lightly-proficient manual writer that’s targeted for beginning users: it’s formatting method is easy and conversion method is basic. This method may also be helpful for those that use github because it has rendering support for this method. For a more traditional approach, nixCraft has an article for that.

Because it was the authors first effort to write a man page, talk was that it was good to use Pod2Man. Pod2man is an application that converts text using Plain Old Document (POD) formatting to traditional manual (man) pages. POD markup is easy to do and pod2man is conveniently pre-installed on most Linux distributions (as it is part of the Perl package).

An example

To get a good idea of what to do, here is a basic example demonstrating the formatting (of a fictitious program 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 fell F<--better>.  It has the ability to output pleasant thoughts, jokes, good memories, optimistic fortunes...  B<dr-smile> I<isn't> a replacement for a professional doctor, please use responsibly and enjoy.  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

Formatting

There is both text formatting and section formatting that is required for a man page.

Text formatting

All the POD text formatting tags needed to know are as follows:

Bold B<text>
Italic I<text>
Link L<http://address.org >
Filename F<file>
email E<gt>name@address.comE<lt>

Man pages use two types of formatting (that I’ve ever seen). That are implemented by POD’s bold formatting and PODS filename-or-italic formatting:

Formatting type Used for
POD Bold formatting
  • Program names
  • Options
  • Manuals
POD Filename formatting
POD Italic formatting
  • Files
  • Keywords
  • Emphasis
  • Arguments
  • Occasionally manuals

Section formatting

There are three section tags that are used in pod2man (that I know of). The pod2man manual refers to these as Command Paragraphs and they are: header/category sections, item sub-sections, and “over” sub-sub-sections for additional descriptions of item sections. References to all of these are in the above example.

  • Header/Category sections are the block descriptors and their contents (like NAME, and DESCRIPTION…).
  • Item sections refer to options generally and often override =over sections for their list item.
  • Over sections refer to option descriptions.

General layout structure

Man pages follow a basic (though liberal) structure can be well represented by this:

NAME
The name of the command, followed by a one-line description of what it does.
SYNOPSIS
A representative invocation of how to run the command and options it has.
DESCRIPTION
A detailed description of the functioning of the command.
OPTIONS
A list of it's options (these are sometimes put in DESCRIPTION).
EXAMPLES
Some examples of common usage.
BUGS
List known bugs.
SEE ALSO
A list of referenced or related commands.
AUTHOR
   Specifying the contact information.
COPYRIGHT
   Specifying the copyright information.

The order of categories varies a bit from man page to man page. The first four categories are almost always the same, however the remaining vary a bit. The above layout is an mnemonic aggregate of category order of the man pages that the author has seen.

Convert pod format to manual page

Pod2man usage is basic:

pod2man dr-smile.pod > dr-smile.1

However, these additional options will probably be wanted to be added, plus compression:

pod2man --section=1 --center="dr-smile manual" --name="dr-smile" --release="1.0" dr-smile.pod | gzip > dr-smile.1.gz

Result

screenshot-manpage

Resources

xuserrun – Run a command on the currently-active user’s X.org server display

xuserrun is a bash script to run a command on the active X.org server display.  This is primarily necessary if from within another environment  (different user, console, cron, boot script…).  xuserrun gathers DISPLAY and user environmental variables via systemd and passes them on to be able to dothis. xuserrun is designed for use with only a single user X.org server display. Running it is basic:

xuserrun xclock -digital

Tto put out a notification:

xuserrun notify-send "Hello, Dave."

It’s available for Arch users in the AUR and is also downloadable on github.

No-think link (redone)

Retyped… again doneover… Forward thinking file linking.

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

Firefox: Defining font type and size

See Firefox/Font type and size.

Follow

Get every new post delivered to your Inbox.

Join 58 other followers