Thursday, March 15, 2018

ASP.Net Core 2 with Postgresql on Linux Part 1: Installing pgAdmin4 on Ubuntu 16.04

For the last 15 years I have had a personal web-based app that I have used to learn new languages and frameworks. 

Starting with Microsoft's .Net 2.0 framework and then moving from Ruby on Rails 3.x, to MeteorJS, and then to .Net Core 1.x, this app has also been used with MySql, SQL Server, MongoDb, and Postgresql as the data access layer. 

Currently, I have ported the app to ASP.Net Core 2 with SQL Server on the Azure cloud. As I was poking around my github repo I thought why not use my Linux Ubuntu 16.04 laptop and port the current ASP.Net Core 2 app to my Linux with Postgresql and place it on Heroku

As I thought about it, my first logical step was to port the data from SQL Server to Postgresql. While I think I am proficient at the command prompt, I had to admit that having a GUI based tool would be a help. Having used pgAdmin on my Rails 3.x project, that is where I leaned. So, step one, get pgAdmin installed on my Ubuntu system. 

Thanks to the data from, this was a much easier transition. 

Here is what I did:

Installed pgAdmin4 using Python3.x (I preferred to avoid encoding related issues):
 $sudo apt-get install virtualenv python3-pip libpq-dev python3-dev  
 $virtualenv -p python3 pgadmin4  
 $cd pgadmin4  
 $source bin/activate  
 $pip3 install  
 $gedit lib/python3.x/site-packages/pgadmin4/  

Copied this to the file:
 import os  
 DATA_DIR = os.path.realpath(os.path.expanduser(u'~/.pgadmin/'))  
 LOG_FILE = os.path.join(DATA_DIR, 'pgadmin4.log')  
 SQLITE_PATH = os.path.join(DATA_DIR, 'pgadmin4.db')  
 SESSION_DB_PATH = os.path.join(DATA_DIR, 'sessions')  
 STORAGE_DIR = os.path.join(DATA_DIR, 'storage')  
 SERVER_MODE = False  

Created the following directories and change the permissions:
 $sudo mkdir "/var/log/pgadmin"  
 $sudo chmod a+wrx "/var/log/pgadmin"  
 $sudo mkdir "/var/lib/pgadmin"  
 $sudo chmod a+wrx "/var/lib/pgadmin"  

Created a file in my /home/mark folder named and copy this to the file (note that your user name will be the folder here):
 cd ~/pgadmin4  
 source bin/activate  
 python3 lib/python3.5/site-packages/pgadmin4/  

Made the file executable:
 $chmod +x /home/mark/  

Then, I installed postgres locally. First I created the file /etc/apt/sources.list.d/pgdg.list, and added a line for the repository:
 deb xenial-pgdg main  

I imported the repository signing key, and update the package lists:
 $wget --quiet -O - | \  
  sudo apt-key add -  
 $sudo apt-get update  

Next, I installed PostgreSQL on Ubuntu, using the apt-get (or other apt-driving) command:
 $apt-get install postgresql  

Finally, after the install of postgresql, I created a user and give them permissions:
 $su -s  
 $su - postgres  
 postgres=# CREATE USER yourUser PASSWORD 'userPassword';  
 postgres=# GRANT ALL ON SCHEMA test TO yourUser;  
 postgres=# GRANT ALL ON ALL TABLES IN SCHEMA test TO yourUser;  
 postgres=# \q  

Now, when I run the ./ command from a terminal and navigate to in my web browser, I see the following:

Coming soon in Part 2, I will detail the process of moving the data from SQL Server to Postgresql.

Thursday, March 08, 2018

Selling Out has been Amazing!

I have been delving into the world of Docker and Containers on both Linux and Microsoft Windows. I was listening to a podcast that recommended the Youtube video, "Containers aka crazy user space fun" that records Jessie Frazelle's keynote at Linux Conf in Australia. At about 1:50 into the video she stated, "who am I?...I work at Microsoft...selling out has been amazing!" There was laughter from this Linux crowd and she continued on to give a great and informative talk on Linux Containers. Typically, selling out is a bad thing and Jessie Frazelle obviously did not mean it in a negative way. On a side note I love that Microsoft loves Linux and I am sure that has resulted in a great working experience for Jessie. Contrary to the populist view that all corporations are evil, this goes to show that companies can...and some do change.

Monday, February 26, 2018

When All Else Fails... Where's the Manual?

How many times have you purchased a product and it required some sort of assembly? You try to put it together only to find you have extra parts left over. As a last resort, you look for the manual. What about when you have to repair it or modify your purchase? Where is the manual?

Concerning software development, if you have a piece of code...a class, a library, or a database table and no one knows who owns it (a.k.a. who created it, is responsible for maintenance, and/or is the source of knowledge for that machine) and something needs to change, either moving to a new system, new feature added, etc, then you have a problem. What typically ensues is similar to what takes place on a factory floor when a piece of equipment that has been running for some time on a production line with out issue needs fixed or new functionality added. 

First, an inquiry is made to the maintenance team asking who is responsible for its upkeep. However, what is found is the maintenance personnel that once created the machine, did the upkeep, and the addition of new functionality is no longer with the company. Then, the maintenance team will review the equipment manual (think dev team documentation here for this analogy). If there is none (which unfortunately is the common case with software that is produced by many dev teams), the team has to consider a few options.

Should they reverse engineer the machine and create a new one? What about simply making the needed changes to the current piece of equipment and risk breaking it? As you know from experience or can imagine, each option has its pros and cons. Yet, wouldn't it be better to have some documentation available to assist? This is why, in my view, documentation is so important when creating software.

Do yourself and others a favor and document with both informative comments in your code as well as external documentation explaining the business rationale as well as a description of your interfaces and objects. 

Saturday, February 10, 2018

Niall Ferguson, author of The Square and the Tower, on TWiT's Triangulation show

Just listened to Niall Ferguson, author of The Square and the Tower, on TWiT's Triangulation show. Yet another reason that the Humanities in general and History specifically is vital in any well rounded education.

Newport on the Levee and the Old Netscape Browser Logo

I was running across the Purple People Bridge from Cincinnati, OH to Newport, KY and noted the digital sign that they have posted on the KY side of the bridge. I was quickly struck with the realization that the Newport logo reminded me of something familiar yet old. After I moment I remembered. The Newport logo reminded me of the old Netscape web browser logo.

Newport on the Levee Sign
Old Netscape Browser Logo

Friday, February 02, 2018

All is well with your approximate existence, mate.

In my Business Programming class that I teach, I was putting together a demo for the students to show the precision, or lack thereof, of certain numeric datatypes. The language is VB.Net. Here is the comment that I have in the code:

'To check floating point division (with Single, Double, and Decimal datatypes), take the quotient and multiply it with the divisor to get a very close approximation to the numerator.

'Why an approximation? "Squeezing infinitely many real numbers into a finite number of bits requires 'an approximate representation.'" (Emphasis mine)


It was with that thought that I realized, I am not sure that I like that it is an approximation. Yet, we must and do live with approximations all day long. This came to light to me back in 2007 when I started to really keep track of my nutrition. Right away I realized that when recording my intake for each meal and snack the data are not exact but rather a range of values. For example, when you eat an apple (medium 3" diameter (182 g)), is the caloric intake always 95 calories? No. Is it ever? Occasionally. The point is, on most occasions we make decisions based on approximations and not exact amounts. Yet, these estimates are good enough for most of life in time and space. If you are a fan of Crocodile Dundee, remember the exchange between he and Sue when discussing his age?

(SUE) How old are you?
(MICK) Dunno. What year is this?
(SUE) You don't know?
(WALT) Time doesn't mean much up here.The Aborigines don't have calendars.
(MICK) I was raised by the local tribe.I asked one of the tribal elders when I was born, and he said,"In the summertime."

Of course, this did not mean that Crocodile Dundee was not born on a specific day, but rather he didn't know what day that was on a Gregorian calendar. Yet, he lived day-to-day the same as if he had known the exact date. 

Mind you, with computer languages and floating point datatypes, there are safe guards so you can rest assured all is well with your approximate existence.

Wednesday, January 31, 2018

QR Codes Kill Kittens?

This morning I was ruffling through old pics in a Dropbox folder and noted an old QR Code that I created about 5 years ago. At the risk of a young feline death, here it is:

I was curious as to their current amount of use and found that some have declared the QR Code useless, others have stated that QR Codes kill kittens, and a few see hope in Snapchat's SnapCodes to keep the concept going. So, in addition to my Bitmoji SnapCode here:

I also created a custom one:

I must admit that I like the looks of the SnapCode better than the old QR Codes. Also, I would venture that more smartphone users have Snapchat installed than a QR Code scanner app.

Tuesday, January 30, 2018

Take a breath, investigate, and deal with it.

This morning while on my laptop another annoying iTunes dialog popped up about installing the latest update. Mind you, iTunes is a good product and I did have it installed back in the day when loading my iPod Shuffle...but that was then. Still, about once a week I would get a "reminder" asking if I wanted to update my installation. I understand that this is a courtesy but it had long ago become an annoyance. After all, I had uninstalled iTunes! Yet, when it would popup again, I would simply close it each time because it only took a second and I could be on my way. But this morning I realized that I was done with the popups and decided to actually take a few minutes and deal with it. 

After taking about 30 seconds to select Edit | Preferences |Never | OK i realized how cathartic! 

Lesson: When that annoying dialog box pops up again, take a breath, investigate the preferences or go online, and take a few minutes to research the setting that schedules the popup, and be rid of it. Ahhh...closure as well as an assurance it will not bother you again!