How Do You Start the Postgres Service on an Ubuntu Linux Server?

Problem scenario
You have Postgres installed on an Ubuntu Linux server.  You want to start the Postgres service. How do you do this?

Solution
Run this command:  service postgresql start

If you want to list the databases on the server, run these three commands:

sudo -i -u postgres
psql
\l

# To exit the psql command prompt, issue this command and press "Enter":
\q

How Do You Use C++ to Retrieve Data from a PostgreSQL Database on Ubuntu Linux?

Problem scenario:  You have C++ and Postgres installed on an Ubuntu Linux server.  How do you write C++ programs to retrieve data from Posgres databases?

Solution
Install the official C++ API for Postgresql.  These directions should work on any Debian distribution of Linux.

As root, do the following from the Linux command prompt:

apt-get -y install libpq-dev g++
cd /usr/bin/
curl http://pqxx.org/download/software/libpqxx/libpqxx-4.0.tar.gz > libpqxx-4.0.tar.gz
tar xvfz libpqxx-4.0.tar.gz
cd libpqxx-4.0
./configure
make
make install

To read more about the official API for C++ and PostgreSQL, see this GitHub link or the official pdxx.org site.

How Do You Troubleshoot This PowerShell Error “Unable to initialize device PRN.”?

Problem scenario
When running a PowerShell script, you receive the error "Unable to initialize device PRN."  

Solution
Use the "echo" reserved word instead of "print".

PRN is what the Windows system name for printer (according to this external posting).

Optional:  If you want to buy a book on PowerShell, click here; you may also want to click here and search for "PowerShell".

What Process Should You Choose to Automate with Robotic Process Automation?

Question
How do you know when a process should be scripted with image recognition and automated via robotic process automation (RPA)?

Answer
Business managers want to know what characteristics a process should have to be a good candidate for robotic process automation.  There are different criteria for selecting a process to automate with RPA.  Here are 10 traits of a software business process that using robotic process automation would add value.

1)  High labor costs for the process.  Clerical or administrative employees can have an expensive hourly rate to a business.  Such activities include workflows data entry with optical character recognition (OCR).

Replicating a sequence of tasks with software can allow a business to save money over time.  Some businesses could use RPA instead of outsourcing certain back-office functions.  RPA could allow the business to keep more records on their own premises using virtual employees, called robots or bots, while lowering their annual costs.   

2)  The process is in a stable enterprise with sufficient communication about a new change to the business that will obviate the task in the near future.  This is more about the environment of the process and less about the process itself.  Some executives may change processes that eliminate the benefit of developing robotic process automation.   Unpredictable businesses may be justifiably reluctant to investing in RPA.  Optimal gains from RPA development come from coherent business operations with adequate communication across the business who are decision-makers governing the process to be automated.  A disadvantage of RPA is that it lends itself to vendor lock-in.

3)  The tasks in the process are pre-determined and repetitive.  Procedures that involve structured data that apply simple logic lend themselves to robotic process automation.  Allowing employees to focus on less mundane tasks can improve business efficiency and improve morale when the cycle of a workflow is automated in an unattended or mostly unattended way.  Employee roles can be transformed in a positive way.

4)  The individual activities involved in changing the state of the data are deterministic insofar as images on the screen are displayed. Deterministic is a quality that involves producing identical output for the same process' input.  Automation can be thought of as computation; the word deterministic is common in the realm of computation.  Random or varying output while holding input constant (keeping the input the same), does not lend itself to automation.

5)  The task is rule-based.  Data (either graphical patterns or strings of text) may need to go through a transition process.  The operations may put the data in different states in a predetermined sequence.  If there are predictable constraints for processing this data, it is a candidate for automation.  

6)  The process is not subjective.  The apparent characters represented in highly obfuscated captchas may be subjective.  RPA can be flexible but only to a certain point.  Processes that are objective tend to be good candidates for RPA.

7)  Human error in the process can be costly.  Having a software robot perform the task can improve accuracy and reliability of the process.

8)  There is no API for the applications involved.  APIs can often be leveraged with consistency and efficiency.  For  processes with no exposed API or a complex, undocumented API, robotic process automation may be the best solution.

9)  It is an end-to-end process that is trans-applicational and has heterogeneous vendors.  If the data must go from  one application to another and the respective vendors are not the same.  Crossing the boundaries of applications and  vendors can be difficult by design.  RPA can open up possibilities for creating a "continual application" (a changing  process that is adaptive and uses artificial intelligence) through multiple applications.  Integrating diverse  applications including the use of Remote Desktop or Putty on Windows workstations is feasible with RPA.

10)  The operations are mostly GUI in nature.  Text based operations can often be automated with programs written in  traditional computer programming languages.

Using PowerShell, How Do You Reverse the Individual Strings in a .txt File While Preserving the Top to Bottom Order of the Lines Themselves?

Problem scenario
You have a list of strings in a .txt file.  You want each string to be in the reverse order from left to right.  You want the strings to remain in their current order from top to bottom.  In other words, you want the content of each line to be reversed. Otherwise you want to preserve the lines in the file (row by row).  For example, the file looks like this:

abc
def
ghi

You want the PowerShell script to transform the above list into this as a separate and new file:

cba
fed
ihg

How do you write such a program?

Solution
<# This program requires one input file, and this file is assigned to the variable "$mainfile".  Change the name and location of 'c:\temp\primarylist.txt' as desired.  The output file will be 'c:\temp\reversed.txt' unless you change it. #>

$mainfile = 'c:\temp\primarylist.txt'
$finalfile = 'c:\temp\reversed.txt'

function reverseString  #reverseString function taken from https://gist.github.com/arebee/ee72fed0a7b5eb90f380
{
  Param(
    [string]$str
  )

  $sb = New-Object System.Text.StringBuilder($str.Length)
  write-verbose $sb.Capacity

  for ($i = ($str.Length - 1); $i -ge 0; $i--)
  {
    [void]$sb.Append($str.Chars($i))
  }

  return $sb.ToString()
}

$transition = get-content $mainfile

$i = 0
$r = Get-Content $mainfile | Measure-Object –Line
$numline = $r.Lines
$coolarray = New-Object string[] $numline    # create an array with the number of lines in the file

foreach ($x in $transition) {      # reverse each line in the array
  $b = reverseString $x
  $coolarray[$i] =  $b
  $i = $i + 1
}

echo $coolarray > $finalfile

How Do You Create a PowerShell Script to Filter a List by Removing Any Line That Matches Patterns or Strings in a Second File?

Problem scenario
You have two files.  One file is the main file you want to modify by removing lines that match specific patterns.  The second file has patterns (or strings) that should not be in a final, filtered list.   How do you filter a file to remove the patterns that match strings in another file?

Solution
# This assumes you want to ignore blank spaces in the second file.  

$var1 = get-content 'c:\temp\mainlist.txt'
$excluded = get-content 'c:\temp\filterlist.txt'

foreach ($exclude in $excluded) { 
  $var1 = echo $var1 | Where-Object { ($_ -notmatch $exclude.trim() ) }
}

echo $var1 >  'c:\temp\finallist.txt'

How Do You Install LAPP Using Ubuntu Linux?

Update October 2020: These were tested to work with Ubuntu 20.x.

Problem scenario
You want to install the four core components that compose the LAPP stack. That is you want to install Apache, Postgres and PHP on Ubuntu Linux (which comes with Perl pre-installed).  How do you do this?

Solution
1.  Install Ubuntu.  If you need directions, see this link.

2.  Run this command:
sudo apt-get -y install php apache2-bin postgresql postgresql-contrib ​php-pgsql libapache2-mod-php

#  Please note that the postgresql-contrib is an optional package.

3. You are done. You can enter the PostgreSQL command line with this command: sudo -u postgres -i

You may also want to see these relevant postings:
How Do You Deploy LAPP with Frontend User Authentication?
How Can You Accept User Input with PHP and Use It in a SQL Command?

How Do You Install Apache Web Server on Your Ubuntu Server when You Receive an Error about “no installation candidate”?

Problem scenario
You tried this command: sudo apt-get install httpd
But you got this error message as a result:

"...E: Package 'httpd' has no installation candidate"

You tried this command as root:  

apt-get install apache2-bin 2.4.7-1ubuntu4.13

But you get this error message as a result:

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package 2.4.7-1ubuntu4.13
E: Couldn't find any package by regex '2.4.7-1ubuntu4.13'

How do you install Apache web server on your Ubuntu server?

Solution
Run this command:  sudo apt-get -y install apache2-bin

How Do You Transfer Data without Using Network Connectivity from a Smart Phone or Tablet to a USB Stick?

Problem scenario
You have a smart phone (iOS, Android, BlackBerry, Microsoft Lumia, Windows 10 Mobile, or Windows Phone etc.) and you have a limited data plan.  You want to copy over (or bring/move) files (e.g., numerous photos).  The problem is that you do not want to use hundreds of megabytes of data from your roaming MiFi/3G/4G monthly plan.  It takes a great deal of manual labor to select the files and then transfer them (e.g., via an email).  You only have standard USB B micro ports on your tablet/smart phone.  You do not trust the WiFi network for your smart phone given recent news about privacy and security and the pictures are not meant for everyone's eyes.  What do you do to transfer over many sensitive files that consume hundreds of MB?

Solution

Copy the files to a USB stick (with sufficient free space) with this cable.  You avoid networks and insecure text messaging altogether.  With a BlackBerry, you can select all with the pictures it has taken.  You can then zip the files into one file and transfer it with very little manual work.  To the right is a picture of a cable that connects regular USB sticks via a female USB A port to your smart phone or tablet computer with the cable's male USB micro-B connector.  To purchase one from Amazon, just click on the image to the right.  

Finally, is the term "micro-USB B" or "USB micro-B"?  One web page (http://www.cablestogo.com/learning/connector-guides/usb) used to use "micro-USB B" nomenclature.  More commonly you will find "USB Micro-B" like what Wikipedia shows.  This cable with a female connector for a regular-sized USB stick is recommended over combination solution with one male USB A connector and a micro-USB A connector and one gender changer adapter because the smart phone has limited electrical power for three accessories (a cable, a male-to-male gender changer adapter, and a USB stick).