How Do You Ingest (or Import) a CSV File into a Postgresql Database Table?

Problem scenario
You want to extract data from a .csv file.  In other words you want to  transform data from a flat file and import it into a database.  Is there an example of how to create a table, format a .csv file, and run a command to import the .csv file into the Postgresql database?

Solution
1.  Here is how to create a table to target for the import or ETL (Extract, Transform, Load) process:

CREATE TABLE continualtable (id int CONSTRAINT firstkey PRIMARY KEY, streetAddress varchar(200), city varchar(100), state char(2), zipcode int, phonenumber varchar(20));

2.  Here is the content of a .csv file that will be imported into the database table created with the above command:

id      streetAddress   city    state   zipcode phonenumber
1,123 Broadway,New York,NY,10001,212-555-5555
2,50 Sunset Blvd,Los Angeles,CA, 90210,310-555-5555
3,400 West Jackson Blvd,Chicago,IL,60611,312-555-5555

3.  From a command terminal of the Linux server with Postgresql, run these commands:

sudo -i -u postgres
psql
COPY continualTable FROM '/tmp/file.csv' WITH CSV HEADER; 

For the COPY command example above remember that "continualTable" is the table name of the target table for this import process, "/tmp/" is the path to your file and your file is named file.csv.  

How Do You Give a Local Windows 2016 Server User Access to Remote into It?

Problem scenario
You have a local user account on a Windows 2016 server (e.g., jdoe).  You want to give it access to be able to start PowerShell sessions from other Windows servers.  What do you do?

Solution
1.  Open PowerShell as Administrator.
2.  Run this command:
Set-PSSessionConfiguration -ShowSecurityDescriptorUI -Name Microsoft.PowerShell
# This is an alternative command provided as a reference in case the above did not work:
# Set-PSSessionConfiguration -Name Microsoft.PowerShell -ShowSecurityDescriptorUI -Force

3.  In the pop up, click "Add..."
4.  Type in the username in the field "Enter the object names..." and click "Check names".
5.  Click "Ok".
6.  Give the user "Read" and "Execute" (by checking the corresponding square boxes).
7.  Click "Ok".

How Do You Create Two Tables with a Shared Column between Them (e.g., Have a Foreign Key Constraint)?

Problem scenario
You want to create two tables in a Postgresql database.  You want the tables to share a column to relate to one another.  You want to implement a foreign key constraint to achieve this goal.  Is there an example of SQL statements to do this?

Solution
Run these two SQL commands that start with the words "CREATE TABLE":

CREATE TABLE table1 (id integer,
    name    varchar(40),
    PRIMARY KEY(id)
);

CREATE TABLE table2 (id int REFERENCES table1,
    name    varchar(40)
);

The second DDL command (i.e., "CREATE TABLE table2") works because the datatype of id is int.  The datatype has to be the same as the primary key's datatype of table1 the subject of the references keyword.  You'll notice that the keywords "CONSTRAINT" and "FOREIGN KEY" are absent from the commands above.

What Do You Do when It Is Too Loud at a Hotel?

Problem scenario
You are at a hotel, and you want to go to sleep.  The freeway, train, or other guest room noise is too loud.  The hotel cannot or will not do anything about the problem.  What do you do?

Possible solutions
You may want to try ear plugs.  But sleeping in them can be uncomfortable.  They can fall out at night. The best solution may be to turn on the heater or A/C. Alternatively you could try turning on the bathroom fan.  This white noise can drown out the problem.  Some turn off when a temperature in the room has been reached.  You can try to handle whichever temperature will likely be unattainable.  It may be uncomfortable, but it is an option.  Some A/C units have a fan option that will remain on independent of the temperature in the room.  You may want to travel with a compact and light-weight white noise machine. There are iPhone and Android applications for your phone to create white noise.

You may also want to install a free decibel meter on your smart phone or tablet computer.  This can be used to prove the noise you are hearing.  You may want to get a baseline in the hallway and move toward the room where the noise is coming from.  Some hotels can be strict about cancelling non-refundable reservations.  A microphone can improve the accuracy of the dB results.  If you have a laptop, you could try installing a free application like this.  If you are old fashioned, you could buy a physical decibel meter.  Sometimes you are not sure if the sound is too loud or not.  Some hotels will listen to polite requests for refunds.  For some hotels, you may need to read about how small claims lawsuits work with a book like this.  Good luck with falling to sleep!

List of Flask (Web-Framework) Books

Beginning Web Development with Python: from prototype to production with flask, tornado and nginx by Andrei Dan
Building Web Applications with Flask by Italo Maia
Data Visualization with Python and JavaScript: Scrape, Clean, Explore & Transform Your Data by Kyran Dale  
Flask Blueprints by Joel Perras
Flask By Example by Gareth Dwyer
Flask Framework Cookbook by Shalabh Aggarwal
Flask Web Development: Developing Web Applications with Python by Miguel Grinberg
Instant Flask Web Development by Ron DuPlain
Learning Flask Framework by Matt Copperwaite and Charles Leifer
Mastering Flask by Jack Stouffer
Python in 24 Hours, Sams Teach Yourself (2nd Edition) by Katie Cunningham 

How Do You Troubleshoot a Syntax Error When Trying to Create a Table with a Primary Key in SQL?

Problem scenario
You are trying to create a table using SQL.  You use the keywords "CONSTRAINT" and "PRIMARY KEY."  For example, your query (or SQL DML command) looks like this:

create table contint ( specialcode char(6) CONSTRAINT PRIMARY KEY, title varchar(40)) ;

When you run the SQL command you get the message '...syntax error at or near "PRIMARY" LINE...'  What should you do to fix this?

Solution
Make sure you give the constraint itself a name.  The syntax is for the name of the constraint to follow the word "CONSTRAINT" and appear before the "PRIMARY KEY" words.

create table contint ( specialcode char(6) CONSTRAINT initialkey PRIMARY KEY, title varchar(50)) ;

Identifying constraints by names, while mandatory, helps future SQL querying.  The error message that is thrown may include the potentially descriptive name of the CONSTRAINT that was violated.  A constraint's name can be modified later. 

A List of Redis Books

Building Scalable Apps with Redis and Node.js by Joshua Johanan
Instant Redis Optimization How-to by Arun Chinnachamy
Instant Redis Persistence by Matt Palmer
Learning Redis by Vinoo Das
Mastering Redis by Jeremy Nelson
Microservices, IoT and Azure: Leveraging DevOps and Microservice Architecture to deliver SaaS Solutions by Bob Familiar
Node Patterns - Databases: Volume I - LevelDB, Redis and CouchDB by Pedro Teixeira
Redis Applied Design Patterns by Arun Chinnachamy
Redis Cookbook: Practical Techniques for Fast Data Manipulation by Tiago Macedo and Fred Oliveira
Redis Essentials by Maxwell Dayvson Da Silva and Hugo Lopes Tavares
Redis in Action by Josiah L. Carlson
Redis PREDICTIVE ANALYTICS REPORT by Gerard Blokdijk
Redis Programming by Example by Agus Kurniawan
Redis: Questions and Answers by George Duckett

How Do You Fix The Ansible Error “Failed to connect to the host via ssh: OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013”?

Problem scenario
You are using Ansible, and you receive an error like this:

coolserver.com | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 56: Applying options for *\r\npercent_expand: unknown key %C\r\n",
    "unreachable": true

How do you fix this?

Solution
On the Ansible control server, find the ansible.cfg file that is governing the Ansible actions.  Back it up.  Eliminate the "control_path" stanza underneath the ssh_connection section.

The second line of these two would need to be deleted:

[ssh_connection]
control_path = ~/.ssh/ansible-ssh-%%C