Build pdo_oci.so (or oci8.so) on SLES 11.4 and Oracle 12.1

I recently had to build pdo_oci.so and I could not find a proper guide to do it. Hopefully this one will help someone.

create a file on document root called test.php

vi /srv/www/htdocs/test.php
<?php
phpinfo();
?>

Browse to http://yourserverip/test.php, on top is the version mine is 5.3.17
Download the correct source http://php.net/releases/ I used this link http://museum.php.net/php5/php-5.3.17.tar.gz
Now copy the downloaded source to ~/php-build

tar -zxvf php-5.3.17.tar.gz
cd php-5.3.17

Oracle Server installed

I have Oracle 12.1 Server installed on the box so I have ensured the my ORACLE_HOME is correct. Read the docs if you want to use the instant client.

[sourcecode language=”shell”] ./configure –with-apxs2=/usr/sbin/apxs2 –with-pdo-oci=shared –with-oci8=shared –with-config-file-path=/etc/php5/apache2/php.ini –with-config-file-scan-dir=/etc/php5/apache2 –with-ldap
make
cd ext/pdo_oci
;edit the config.m4 file
vi config.m4
[/sourcecode]

search for 11
and change

case $PDO_OCI_VERSION in
9.0|10.1|10.2|11.1|11.2)
PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD)
;;

to
case $PDO_OCI_VERSION in
9.0|10.1|10.2|11.1|11.2|12.1|12.2)
PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD)
;;

do a pwd make sure you are in ext/pdo_oci directory

[sourcecode language=”shell”] phpize
./configure –enable-shared
make
[/sourcecode]

Instant Client

For the instant client you might get error like:
checking Oracle Instant Client library version compatibility… configure: error: Link from /usr/lib/oracle/libclntsh.so to /usr/lib/oracle/libclntsh.so.*

[sourcecode language=”shell”] cd /usr/lib/oracle
sudo ln libclntsh.so.12.1 libclntsh.so
[/sourcecode] Then configure like
[sourcecode language=”shell”] ./configure –with-apxs2=/usr/bin/apxs2 –with-pdo-oci=shared,instantclient,/usr/lib/oracle –with-oci8=shared,instantclient,/usr/lib/oracle
[/sourcecode]

To Build the shared object

[sourcecode language=”shell”] cd ext/oci8/
phpize
./configure –enable-shared -with-oci8=instantclient,/usr/lib/oracle
make
[/sourcecode] OR PDO_OCI
[sourcecode language=”shell”] cd ext/pdo_oci
phpize
./configure –enable-shared -with-pdo-oci=instantclient,/usr/lib/oracle
make

now there should be a folder modules

cd modules
ls -l ;should show a pdo_oci.so

sudo cp pdo_oci.so /usr/lib64/php5/extensions
cd /etc/php5/conf.d/
sudo vi pdo_oci.ini

Add the following to the file :

; comment out next line to disable pdo_oci extension in php
extension=pdo_oci.so

tail -f /var/log/apache2/error.log
if you get
Unable to load dynamic library ‘pdo_oci.so’ (tried: /usr/lib/php/[SOMENUMBER]/pdo_oci.so (libmql1.so: cannot open shared object file: No such file or directory)

Add Oracle libs to the LD_LIBRARY_PATH

cd /etc/ld.so.conf.d
#Create file oracle and add /usr/lib/oracle
sudo vi oracle

and if that does not work then

cd /etc/apache2/
sudo vi envvars 
#and add 
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/oracle
#to the end of the file

Restart the apache server or you can do
php -i | grep pdo
to see if its loaded.

Python update to fix Kodi on linux (Ubuntu and mint)

I had issues with my Kodi 17.6 on linux. I have noticed errors involving cryptography and ffi. Here is the procedure that I followed to fix it.
Open a Terminal and do the following:

 sudo apt-get install build-essential libssl-dev libffi-dev python-dev python-pip

After its done then install cryptography for python

pip install cryptography

It will prompt to install update pip BUT DONT DO THAT IT WILL BREAK THINGS.

PHP 7.0 to PHP 5.6 on Ubuntu / Linux Mint

Parse error: syntax error, unexpected ‘new’ (T_NEW) in /usr/share/php/MDB2/Driver/pgsql.php on line 925

The problem is that MDB2 is not supported for PHP7.0
It is better to use PDO PHP PDO but if you cant then here is how to downgrade to PHP5.6.

dpkg -l | grep php| awk '{print $2}' |tr "\n" " "

I like to do it manually so copy the above output to the command

sudo apt-get purge libapache2-mod-php7.0 php php-common php-gettext php-mdb2 php-pear php-pgsql php-phpseclib php-xml php7.0 php7.0-cli php7.0-common php7.0-dev php7.0-fpm php7.0-gd php7.0-intl php7.0-json php7.0-mbstring php7.0-mcrypt php7.0-mysql php7.0-opcache php7.0-pgsql php7.0-readline php7.0-xml php7.0-zip 
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php5.6

Verify php 5.6

php -v

PHP 5.6.36-1+ubuntu16.04.1+deb.sury.org+1 (cli)
Then restart apache2.0

sudo /etc/init.d/apache2 restart

Dont forget to install PEAR again

sudo apt-get install php-mdb2
apt-cache search mdb2
sudo apt-get install php-mdb2-driver-pgsql
sudo apt-get install php5.6-pgsql

Javascript Essentials ES6

Object to String Array of the object keys

 const strArrKeys = Object.keys(jsObjectVariable); 

Object to Array with Key Value pairs

let theobj = { key1: "value1", key2: "value2" }
Object.entries(theobj).forEach(eachKeyVal =&amp;amp;amp;amp;amp;amp;gt;
   { console.log("Key is " + eachKeyVal[0] + " and value is " + eachKeyVal[1]) }); 

Array from object values

 jsObjectVariable = { one : 1, two: 2, three: { temp1: "t1", temp2: "t2" } } const strArr = Object.keys(jsObjectVariable) // Returns ARRAY of the keys .map(k =&amp;amp;amp;amp;gt; jsObjectVariable[k] ); // Retruns an Array of values console.log(strArr); const strArr2 = Object.keys(jsObjectVariable) // Returns ARRAY of the keys .map(k =&amp;amp;amp;amp;gt; { return jsObjectVariable[k] } ); // Retruns an Array of values console.log(strArr2); jsARRVariable = [(one =&amp;amp;amp;amp;gt; 1),(two =&amp;amp;amp;amp;gt; 2)]; const strArr3 = jsARRVariable.map((k,v) =&amp;amp;amp;amp;gt; {return v;} ); // Returns array of values console.log(strArr3); 

Make a copy of the object.

cont newObject = {...oldObject};

Make a copy of the array.

cont newArray = [...oldArray];

Add values to an Array immutably.
Dont use push use concat, it will make a copy of the array.
Add an integer called counter to an array called results:

cont newObject = {
    ...oldObject,
    results: oldObject.results.concat(oldObject.counter)
};

Delete values from an Array immutably.

const idToDelete = 4;
const newArray = [...oldArray];
newArray.splice(idToDelete,1);

OR

newArray = oldArray.filter((result,index) =&amp;amp;amp;amp;gt; index !== idToDelete);

You can also create dynamic object keys (Object Names based on variables) and use them

var example = {one : 'something', two: 'somethingElse'};
var test = {
    [example.one]: true,
    [example.two]: function () { console.log('This is SomethingElse function Result');},
};

console.log(test.something);
test.somethingElse();

IN ES5 we used to:

var key = 'dynamicKey';
var o = {};
o[key] = 'value';

But in ES6, when creating an object literal, you can do this:

Continue reading “Javascript Essentials ES6”

Java easily convert from char or string to ENUM

One of my popular ways to make my code more readable is to make use of an ENUM.

If you have some “if” or “switch” statement:

             char myChar = 'D';
             if (myChar=='H') {
              //SOME CODE
              } else if (myChar=='V') {
                //SOME OTHER CODE
                 }

it does not say much about the functionality thats why I use enums

public enum myType {
        HORIZONTAL("H"),
        VERTICAL("V");
        private char directionToken;
        
        public static myType fromChar(char searchchar) {
            for (myType st : myType.values()) {
                if (st.directionToken == searchchar) {
                    return st;
                }
            }
            return null;
        }
        
        private myType(String transToken) {
            this.directionToken = transToken.charAt(0);
        }

        public char directionToken() {
            return directionToken;
        }
    }    

.....

             myType currRecordType = myType.fromChar(linechar[43]);
             switch (currRecordType) {
                 case HORIZONTAL:{
                     ...
                     break;
                     }
                     
                 case  VERTICAL:{
                     ...
                     break;
                 }
             }

Python Dictionaries and Panda

Here are some quick references to Python Dictionaries and Panda include

#Dictionaries
#Create
cities_in_europe = {'spain':'madrid', 'france':'paris', 'germany':'berlin', 'norway':'oslo' }

#Read value back
cities_in_europe['france']

#Add to Dictionaries
cities_in_europe['italy'] = 'venice'

#Change a value
cities_in_europe['italy'] = 'rome'

#"key" in dicarr
'italy' in delcities_in_europe #-&gt; returns true

#delete a key
del(cities_in_europe['italy'])

print(cities_in_europe)

#N Dimention Dictionaries
europe = { 'spain': { 'capital':'madrid', 'population':42.33 },
'france': { 'capital':'paris', 'population':63.02 },
'germany': { 'capital':'berlin', 'population':78.62 },
'norway': { 'capital':'oslo', 'population':8.078 } }

#Get Single value
europe['france']['capital']
europe['france']['population']

# Print out the capital of France
print(europe['france']['capital'])

# Add One more Element
data = {'capital':'rome','population':59.83}

# Add data to europe under key 'italy'

europe['italy'] = data

#Add in one line
europe['england'] = {'capital':'london','population':78.88}

# Print europe

print(europe)
Pre Defined Lists
# Pre-defined lists
names = ['United States', 'Australia', 'Japan', 'India', 'Russia', 'Morocco', 'Egypt']
dr = [True, False, False, False, True, True, True]
cpc = [809, 731, 588, 18, 200, 70, 45]

import pandas as pd

my_dict = {'country':names ,
'drives_right':dr ,
'cars_per_cap':cpc }

# Build a DataFrame cars from my_dict: cars

cars = pd.DataFrame(my_dict)
print(cars)

row_labels = ['US', 'AUS', 'JAP', 'IN', 'RU', 'MOR', 'EG']

# Specify row labels of cars

cars.index = row_labels

print(cars)
Panda from CSV File

———- CVS FILE ————–
,country,capital,area,population
BR,Brazil,Brasilia,8.516,200.4
RU,Russia,Moscow,17.10,143.5
IN,India,New Delhi,3.286,1252
CH,China,Beijing,9.597,1357
SA,South Africa,Pretoria,1.221,52.98


import pandas as pd

brics = pd.read_csv("path/to/brics.csv", index_col = 0)
print(brics)

Column and Row Access
print(brics['country'])
print(type(brics['country']))
#Gives you &lt;class 'pandas.core.series.Series'&gt;

print(brics[['country']])
print(type(brics[['country']]))
#Gives you &lt;class 'pandas.core.frame.DataFrame'&gt;

#Two Columns
print(brics[['country','capital']])

#Row Access
brics[0:3] # Rows 0,1,2
brics[3:6] # Rows 3,4,5

#loc and iloc
brics.loc['RU'] #Selects row for RU
brics.iloc[1]
brics.loc[['BR','SA']] #Selects ROW BR and SA
brics.iloc[[0,4]]

#Select Area for SA
brics.loc['SA','area'])

# Capital and area for SA and RU
brics.loc[['SA','RU'],['capital','area']])
brics.loc[['RU','MOR'],['country','area']]
#Combine loc and iloc using ix
brics.ix[[4,5],['country','capital']]
brics.ix[4:6,['country','capital']]

#Slice-ing loc
brics.loc[:,'area']) #As Series
brics.loc[:,['area']]) #As DataFrame
brics.loc[:,['area','capital']]) #As DataFrame Area , Capital

Linux Mint Distribution Comparison to Ubuntu and Debian

My favourite Linux Distribution is Linux Mint and every so often you need to add a custom deb resource and the only ones out there is for Ubuntu or debian.

The latest Mint code names can be found at:

https://linuxmint.com/download_all.php

To help here is a list of distribution names from Ubuntu.

https://wiki.ubuntu.com/Releases

Ubuntu 19.10

Eoan Ermine

Release Notes

October 17, 2019

July 2020

July 2020

Ubuntu 18.04.4 LTS

Bionic Beaver

Changes

February 12, 2020

April 2023

April 2028

Ubuntu 18.04.3 LTS

Bionic Beaver

Changes

August 8, 2019

April 2023

April 2028

Ubuntu 18.04.2 LTS

Bionic Beaver

Changes

February 15, 2019

April 2023

April 2028

Ubuntu 18.04.1 LTS

Bionic Beaver

Changes

July 26, 2018

April 2023

April 2028

Ubuntu 18.04 LTS

Bionic Beaver

Release Notes

April 26, 2018

April 2023

April 2028

Ubuntu 16.04.6 LTS

Xenial Xerus

Changes

February 28, 2019

April 2021

April 2024

Ubuntu 16.04.5 LTS

Xenial Xerus

Changes

August 2, 2018

April 2021

April 2024

Ubuntu 16.04.4 LTS

Xenial Xerus

Changes

March 1, 2018

April 2021

April 2024

Ubuntu 16.04.3 LTS

Xenial Xerus

Changes

August 3, 2017

April 2021

April 2024

Ubuntu 16.04.2 LTS

Xenial Xerus

Changes

February 16, 2017

April 2021

April 2024

Ubuntu 16.04.1 LTS

Xenial Xerus

Changes

July 21, 2016

April 2021

April 2024

Ubuntu 16.04 LTS

Xenial Xerus

Release Notes

April 21, 2016

April 2021

April 2024

Ubuntu 14.04.6 LTS

Trusty Tahr

Changes

March 7, 2019

April 2019

April 2022

Ubuntu 14.04.5 LTS

Trusty Tahr

Changes

August 4, 2016

April 2019

April 2022

Ubuntu 14.04.4 LTS

Trusty Tahr

Changes

February 18, 2016

HWE August 2016

April 2022

Ubuntu 14.04.3 LTS

Trusty Tahr

Changes

August 6, 2015

HWE August 2016

April 2022

Ubuntu 14.04.2 LTS

Trusty Tahr

Changes

February 20, 2015

HWE August 2016

April 2022

Ubuntu 14.04.1 LTS

Trusty Tahr

Changes

July 24, 2014

April 2019

April 2022

Ubuntu 14.04 LTS

Trusty Tahr

Release Notes

April 17, 2014

April 2019

April 2022

Debian can be found in a file called

cat /etc/debian_version

18.04  bionic     buster  / sid
17.10  artful     stretch / sid
17.04  zesty      stretch / sid
16.10  yakkety    stretch / sid
16.04  xenial     stretch / sid
15.10  wily       jessie  / sid
15.04  vivid      jessie  / sid
14.10  utopic     jessie  / sid
14.04  trusty     jessie  / sid
13.10  saucy      wheezy  / sid
13.04  raring     wheezy  / sid
12.10  quantal    wheezy  / sid
12.04  precise    wheezy  / sid
11.10  oneiric    wheezy  / sid
11.04  natty      squeeze / sid
10.10  maverick   squeeze / sid
10.04  lucid      squeeze / sid

Oracle Generate Merge Script

I have found this script and its so useful, I had to share it again.

Anytime you want to sync your data from the production database to the test database you can use this script.

JUST BE VERY CAREFUL TO NOT UPDATE YOUR PRODUCTION DATA WITH TEST DATA.

I like to run it on the test database, to be safe I create a DB link with a user that just have only Read Only access on the production data, to ensure you don’t update production data.

If you have more than one test database its always advisable to test it first between test databases.

This script wont update any data it will only generate the merge statement that you can use to update your data.

RazorFink Table Merge


--------------------------------------------------------------------------------
--Meta SQL for scaffolding table merge statements
--  Usage:
--    Execute SQL
--    export/copy lines to sql file
--    make necessary edits
--  TODO:
--    make all column references explicit
--------------------------------------------------------------------------------

WITH
    target AS
    (SELECT
        upper(trim(:owner))      AS owner,
        upper(trim(:table_name)) AS table_name
      FROM
        dual
    ),
    all_cols AS
    (SELECT
        atc.owner       AS owner,
        atc.table_name  AS table_name,
        atc.column_name AS column_name,
        atc.column_id   AS column_id,
        atc.data_type   AS data_type,
        atc.data_length AS data_length
      FROM
        all_tab_cols atc,
        target
      WHERE
        atc.owner           = target.owner      AND
        atc.table_name      = target.table_name AND
        atc.hidden_column  != 'YES'             AND
        atc.virtual_column != 'YES'
      ORDER BY
        column_id
    ),
    pk_cols AS
    (SELECT
        ac.owner           AS owner,
        ac.table_name      AS table_name,
        acc.column_name    AS column_name,
        acc.position       AS position,
        all_cols.column_id AS column_id
      FROM
        all_constraints ac,
        all_cons_columns acc,
        all_cols
      WHERE
        ac.owner            = all_cols.owner AND
        ac.table_name       = all_cols.table_name AND
        ac.constraint_type  = 'P' AND
        acc.owner           = ac.owner AND
        acc.table_name      = ac.table_name AND
        acc.constraint_name = ac.constraint_name AND
        acc.column_name     = all_cols.column_name
      ORDER BY
        acc.position
    ),
    data_cols AS
    (SELECT
        owner,
        table_name,
        column_name,
        column_id
      FROM
        all_cols
    MINUS
    SELECT
        owner,
        table_name,
        column_name,
        column_id
      FROM
        pk_cols
      ORDER BY
        column_id
    ),
    sql_parts AS
    (SELECT
        'SELECT'                 AS sql_select,
        'FROM'                   AS sql_from,
        'WHERE'                  AS sql_where,
        'ORDER BY'               AS sql_order_by,
        ';'                      AS sql_semi,
        'MERGE INTO'             AS sql_merge_into,
        'USING'                  AS sql_using,
        'ON'                     AS sql_on,
        'WHEN MATCHED THEN'      AS sql_when_matched,
        'UPDATE SET'             AS sql_update_set,
        'WHEN NOT MATCHED THEN'  AS sql_when_not_matched,
        'INSERT'                 AS sql_insert,
        'VALUES'                 AS sql_values,
        '('                      AS sql_paren_open,
        ')'                      AS sql_paren_close,
        chr(10)                  AS sql_lf,
        '  '                     AS sql_t,
        MAX(LENGTH(column_name)) AS max_col_length
      FROM
        dual,
        all_cols
    )
  --------------------------------------------------------------------------------
  SELECT
      STATEMENT
    FROM
      (SELECT
          1              AS statement_order,
          rownum         AS row_order,
          sql_merge_into AS STATEMENT
        FROM
          sql_parts
      UNION
      SELECT
          2      AS statement_order,
          rownum AS row_order,
          sql_parts.sql_t
          ||lower(owner)
          ||'.'
          ||lower(table_name)
          ||' o' AS STATEMENT
        FROM
          target,
          sql_parts
      UNION
      SELECT
          3         AS statement_order,
          rownum    AS row_order,
          sql_using AS STATEMENT
        FROM
          sql_parts
      UNION
      SELECT
          4      AS statement_order,
          rownum AS row_order,
          sql_t
          ||sql_paren_open AS STATEMENT
        FROM
          sql_parts
      UNION
      SELECT
          5      AS statement_order,
          rownum AS row_order,
          sql_t
          ||sql_t
          ||sql_select AS STATEMENT
        FROM
          sql_parts
      UNION
      SELECT
          6      AS statement_order,
          rownum AS row_order,
          sql_t
          ||sql_t
          ||sql_t
          ||sql_t
          || rpad(lower(all_cols.column_name), sql_parts.max_col_length, ' ')
          ||rpad(' AS '
          ||all_cols.column_name
          ||(
            CASE
              WHEN lead(all_cols.column_id) over (order by all_cols.column_id) IS NOT NULL
              THEN ','
              ELSE NULL
            END), sql_parts.max_col_length+6, ' ')
          ||'-- '
          ||all_cols.data_type
          ||sql_parts.sql_paren_open
          ||all_cols.data_length
          ||sql_parts.sql_paren_close AS STATEMENT
        FROM
          all_cols,
          sql_parts
      UNION
      SELECT
          7      AS statement_order,
          rownum AS row_order,
          sql_t
          ||sql_t
          ||sql_t
          ||sql_from
        FROM
          sql_parts
      UNION
      SELECT
          8      AS statement_order,
          rownum AS row_order,
          sql_parts.sql_t
          ||sql_parts.sql_t
          ||sql_parts.sql_t
          ||sql_parts.sql_t
          || lower(target.owner
          ||'.'
          ||target.table_name) AS STATEMENT
        FROM
          target,
          sql_parts
      UNION
      SELECT
          9      AS statement_order,
          rownum AS row_order,
          sql_t
          ||sql_t
          ||sql_t
          || sql_order_by AS STATEMENT
        FROM
          sql_parts
      UNION
      SELECT
          10       AS statement_order,
          position AS row_order,
          sql_t
          ||sql_t
          ||sql_t
          ||sql_t
          || lower(column_name)
          || (
            CASE
              WHEN lead(position) over (order by position) IS NOT NULL
              THEN ','
              ELSE NULL
            END )
        FROM
          pk_cols,
          sql_parts
      UNION
      SELECT
          11     AS statement_order,
          rownum AS row_order,
          sql_t
          ||sql_paren_close
          ||' n' AS STATEMENT
        FROM
          sql_parts
      UNION
      SELECT
          12     AS statement_order,
          rownum AS row_order,
          sql_on AS STATEMENT
        FROM
          sql_parts
      UNION
      SELECT
          13     AS statement_order,
          rownum AS row_order,
          sql_t
          ||sql_paren_open AS STATEMENT
        FROM
          sql_parts
      UNION
      SELECT
          14       AS statement_order,
          position AS row_order,
          sql_t
          ||sql_t
          || rpad('o.'
          ||lower(column_name), max_col_length+2, ' ')
          ||' = '
          ||'n.'
          ||lower(column_name)
          ||(
            CASE
              WHEN lead(column_id) over (order by position) IS NOT NULL
              THEN ' AND'
              ELSE NULL
            END) AS STATEMENT
        FROM
          pk_cols,
          sql_parts
      UNION
      SELECT
          15     AS statement_order,
          rownum AS row_order,
          sql_t
          ||sql_paren_close AS STATEMENT
        FROM
          sql_parts
      UNION
      SELECT
          16               AS statement_order,
          rownum           AS row_order,
          sql_when_matched AS STATEMENT
        FROM
          sql_parts
      UNION
      SELECT
          17     AS statement_order,
          rownum AS row_order,
          sql_t
          || sql_update_set AS STATEMENT
        FROM
          sql_parts
      UNION
      SELECT
          18     AS statement_order,
          rownum AS row_order,
          sql_t
          ||sql_t
          || rpad('o.'
          ||lower(column_name), max_col_length+2, ' ')
          ||' = '
          ||'n.'
          ||lower(column_name)
          ||(
            CASE
              WHEN lead(column_id) over (order by column_id) IS NOT NULL
              THEN ','
              ELSE NULL
            END) AS STATEMENT
        FROM
          data_cols,
          sql_parts
      UNION
      SELECT
          19                   AS statement_order,
          rownum               AS row_order,
          sql_when_not_matched AS STATEMENT
        FROM
          sql_parts
      UNION
      SELECT
          20     AS statement_order,
          rownum AS row_order,
          sql_t
          ||sql_insert AS STATEMENT
        FROM
          sql_parts
      UNION
      SELECT
          21     AS statement_order,
          rownum AS row_order,
          sql_t
          ||sql_t
          ||sql_paren_open AS STATEMENT
        FROM
          sql_parts
      UNION
      SELECT
          22     AS statement_order,
          rownum AS row_order,
          sql_t
          ||sql_t
          ||sql_t
          || 'o.'
          ||lower(column_name)
          ||(
            CASE
              WHEN lead(column_id) over (order by column_id) IS NOT NULL
              THEN ','
              ELSE NULL
            END) AS STATEMENT
        FROM
          all_cols,
          sql_parts
      UNION
      SELECT
          23     AS statement_order,
          rownum AS row_order,
          sql_t
          ||sql_t
          ||sql_paren_close AS STATEMENT
        FROM
          sql_parts
      UNION
      SELECT
          24     AS statement_order,
          rownum AS row_order,
          sql_t
          || sql_values
        FROM
          sql_parts
      UNION
      SELECT
          25     AS statement_order,
          rownum AS row_order,
          sql_t
          ||sql_t
          ||sql_paren_open AS STATEMENT
        FROM
          sql_parts
      UNION
      SELECT
          26     AS statement_order,
          rownum AS row_order,
          sql_t
          ||sql_t
          ||sql_t
          || 'n.'
          ||lower(column_name)
          ||(
            CASE
              WHEN lead(column_id) over (order by column_id) IS NOT NULL
              THEN ','
              ELSE NULL
            END) AS STATEMENT
        FROM
          all_cols,
          sql_parts
      UNION
      SELECT
          27     AS statement_order,
          rownum AS row_order,
          sql_t
          ||sql_t
          ||sql_paren_close AS STATEMENT
        FROM
          sql_parts
      UNION
      SELECT
          28       AS statement_order,
          rownum   AS row_order,
          sql_semi AS STATEMENT
        FROM
          sql_parts
      )
    ORDER BY
      statement_order,
      row_order ;

Pivot Tables in PostgreSQL

To use the pivot table function you need the tablefunc extention for postgres.

CREATE extension tablefunc;

I liked this post : vertabelo post it helped me but I want to add to that one, so please read it first. Then come back.
So consider this SQL

select IDENTIFIER, CATAGORIES, SUM(value) as VALUES 
from TABLE 
group by IDENTIFIER, CATAGORIES

So lets consider our categories being 3 letter Months ie (Jan, Feb,….) and we want to show payments for each month.

select SOME_PRIMARY_KEY, 
       to_char (DATE_PAYMENT_MADE,  ''Mon'')  as MONTH_CODES,
       SUM(PAYMENTS) as TOT_PAID 
from TABLE 
group by SOME_PRIMARY_KEY, to_char (DATE_PAYMENT_MADE,  ''Mon'')

Now to run this have each month as a column we would

 SELECT *   FROM crosstab( '
     select SOME_PRIMARY_KEY, 
            to_char (DATE_PAYMENT_MADE,  ''Mon'')  as MONTH_CODES,
            SUM(PAYMENTS) as TOT_PAID 
      from TABLE 
group by SOME_PRIMARY_KEY, to_char (DATE_PAYMENT_MADE,  ''Mon'')
') 
AS final_result(MyPK character varying(20) , Jan numeric,Feb numeric,Mar numeric,Apr numeric,May numeric,Jun numeric,Jul numeric,Aug numeric,Sep numeric, Oct numeric, Nov numeric,Dec numeric) 
)

This does not give us the desired result since it will fill up from the fist column the values and not assign it to the correct column. To get the desired result we will have to add a second parameter to crosstab

 SELECT *   FROM crosstab( '
     select SOME_PRIMARY_KEY, 
            to_char (DATE_PAYMENT_MADE,  ''Mon'')  as MONTH_CODES,
            SUM(PAYMENTS) as TOT_PAID 
      from TABLE 
group by SOME_PRIMARY_KEY, to_char (DATE_PAYMENT_MADE,  ''Mon'')
',
  $$VALUES ('Jan'::text),('Feb'),('Mar'),('Apr'),('May'),('Jun'),('Jul'),('Aug'),('Sep'),('Oct'),('Nov''),('Dec')$$
) 
AS final_result(MyPK character varying(20) , Jan numeric,Feb numeric,Mar numeric,Apr numeric,May numeric,Jun numeric,Jul numeric,Aug numeric,Sep numeric, Oct numeric, Nov numeric,Dec numeric) 
)

Java 8 Lambda – Simple explanation of the Consumer Interface

I have not found a simple explanation of how the consumer interface works and how to use it in a lambda expression. Hopefully I will help you guys to see how easy it is to use and you will also simplify your code.
The legacy way to create a List and loop through it :

public class ConventionalForLoop {
    
    public static void main(String[] args) {
        List<Integer> il = new ArrayList<>();
        il.add(10); il.add(15); il.add(20); il.add(25);

        for (Iterator<Integer> i = il.iterator(); i.hasNext();) {
            Integer item = i.next();
            System.out.println("For Loop Value :" + item);
        }
    }
}
Now with Java 8 we can use a Consumer Interface and for explanation I have declared it.

public class ShowConsumer {
    public static void main(String[] args) {
        class ConsumeInt implements Consumer<Integer>
            {
                @Override
                public void accept(Integer i) {
                    System.out.println("Value From Consumer :" + i.toString());
                }
            }
        List<Integer> arrl = Arrays.asList(10,15,20,25);
        ConsumeInt ci = new ConsumeInt();
        arrl.forEach(ci);
    }
With the lambda expression it is very simple :

public class ShowConsumer {
    public static void main(String[] args) {
        List<Integer> arrl = Arrays.asList(10,15,20,25);
        arrl.forEach(i -> System.out.println("Value From Consumer :" + i.toString()));
    }
}