How Do You Troubleshoot a PHP Error “call to undefined function pg_connect()” So Your Script Can Log into a Postgres Database?

Problem scenario
You are trying to use a .php script on the back end to connect to your PostgreSQL database.  However, you get an error like this when you try to run it:  'PHP Fatal error:  Call to undefined function pg_connect() in '

Solution
Install php5-pgsql.  For Ubuntu you would run a command like this:  sudo apt-get install php5-pgsql

How Do You Fix “Scanning Plug and Play compliant hardware” Message That Does Not Go Away?

Problem scenario
Flash drives and USB ports are not working properly in Windows.  You are not able to use a variety of working USB sticks.  These flash drives have files that you need.  When you go to Device Manager and right click "Universal Serial Bus controllers" or other sub-devices, you see this error "Scanning Plug and Play compliant hardware."  It never goes away.  The Device Manager window becomes stuck.

How do you get your USB devices to work properly?

Solution
1.  Physically remove USB devices from your computer.
2.  In Windows, go to Device Manager and expand "Universal Serial Bus controllers"
3.  For each device you see under "Universal Serial Bus controllers," right click each one and go to "Uninstall."  After they have all been uninstalled there will be no "Universal Serial Bus controllers" option in Device Manager.  This is what you want.  
4.  Reboot your computer.  You are done.

Advertising
When computers are malfunctioning, they remind you of the importance of backing up data.  Click on this for a USB stick that is great for travel.  Click on this for an external USB hard drive.  

Could you use a new USB device? We can provide some ideas.  If you want a USB splitter, buy this USB 3.0 version here. Click on this for a camera.  Click on this for an iPod.  Click on this for a scanner.  Click on this for a printer.  This keyboard is great for travel, and it is compatible with Windows 7, 8, and 10.  You may want the white version because it could be easier to see in a suitcase.  Click here for a lightweight wireless mouse.  You may want to browse affordablemid-level, or expensive laptops on Amazon.  You may want a new desktop computer; for an affordable option, see this one.  For a very high end desktop, you may want to click on this link.

How Do You Find the PID when You only Know It by the Task Name in the Task Manager?

Problem scenario
You have an application (in Windows) running, and you want to terminate it with PowerShell.  You want to find running program's PID.  But you only know its name in Task Manager.  

How do you obtain the Process ID (identification number) of a program (or application) in Windows when you only know the Task Manager name of the program (or application)?

Solution
1.  Open Task Manager (e.g., Ctrl-Shift-Escape)
2.  Right click the name of the Task as you see it in the "Applications" tab.  Click "Go to Process."
3.  You will now be highlighting the process.  Go to View -> Select Columns and check the "PID (Process Identifier)" option.
4.  Now you should see the "PID."
5.  If you want to terminate this application, open PowerShell as Administrator.  
6.  Issue this command from the PowerShell command prompt: kill xxxx 
(where xxxx is the PID)

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?