Monday, January 06, 2014

Compile Postgres in Windows with GSSAPI

Configuration Phase
  1. Install the 64 bit versions of OpenSSL and MIT Kerberos
  2. Get the professional version of Visual Studio 2010 or 2012.
  3. Open the 64Bit of the Visual Studio Command Prompt (not the 32 bit version)
  4. cd to src\tools\msvc in the folder that contains Postgres’ source code
  5. Change the
add these lines:

includes => 'C:\\Program Files\\MIT\\Kerberos\\include:C:\\OpenSSL-Win64\\include',
libraries => 'C:\\Program Files\\MIT\\Kerberos\\lib\\amd64:C:\\OpenSSL-Win64\\lib',
“iconv   => undef,”
change the krb5 and ssl lines to:
krb5    => 'C:\\Program Files (x86)\\MIT\\Kerberos',    # --with-krb5=
openssl => 'C:\\OpenSSL-Win64',    # --with-ssl=

Build Phase
  1. in the vs command prompt, type Build
  2. When done, if no errors, then type Install C:\PathWhereYouWanToInstallPostgres
  3. Go to the folder where OpenSSL is installed
  4. Search in the folder and subfolders for libeay32 and ssleay.dll and copy those files
  5. Go to the folder where it Postgres was installed (C:\PathWhereYouWanToInstallPostgres) 
  6. Go to the BIN folder and paste libeay32 and ssleay.dll
  7. Start the regular command prompt in that folder and call pg_ctl -D PATH_TO_YOUR_DATA_FOLDER

Please refer to the Postgresql documentation on how to configure GSSAPI in an installed Postgresql service here.

Tuesday, November 19, 2013

How to use Windows SSO with OpenXava

One of the nice things about the .NET web environment is the dead easy way to implement Single Sign On in your web apps through Active Directory authentication. In the Java world there are multiple alternatives to use Windows’ Single Sign On with Java based web apps. One of those alternatives is Waffle. Waffle allows your Java web app to authenticate against Active Directory groups (and users). The only caveat is that your web server needs to be running in Windows, which kind of makes sense.

In this article, you will learn the steps required to have your OpenXava web application use Waffle to authenticate your Windows users.

The first step is to download Waffle from their site and then copy the JAR files outlined in to the OpenXava’s tomcat server.

In your OpenXava project, create servlets.xml in the Web-inf, containing the following:

<!-- the role name (the domain gorup) must be entered EXACTLY as it appears in AD. It is case sensitive -->

Demo Application

Add a new file called filters.xml to Web-inf:


After creating the filters.xml file, create the a context.xml file in the META-INF folder (not Web-inf):

<?xml version="1.0" encoding="UTF-8"?>
<Valve className="waffle.apache.NegotiateAuthenticator" />
<Realm className="waffle.apache.WindowsRealm" />

That’s it! that will limit access to members of YOURDOMAIN\YourADGroup and the users that visit the site will have their Windows credential pass-thorugh their browser. Please consult OpenXava and Waffle on how to get the current username in order to handle custom logic based on the current user’s Active Directory groups.

Wednesday, November 13, 2013

Data Science for Business by Foster Provost & Tom Fawcett O’Reilly Media

Data Science for Business is a book that makes a phenomenal job teaching the fundamental concepts of Data Science (a.k.a. Data Analysis and Data Mining). Foster Provost and Tom Fawcett explain in plain English, clear examples and beginner-level math the processes surrounding Data Science and the basics of its algorithms.

The authors go over the various steps of the CRISP method using situations found in the real world such as Customer Churn and Online Advertising. The most common data analysis models are reviewed and explained in detail such as Clustering, Decision Trees and Support Vector Machines. Extensive explanation is given to the difference between supervised and unsupervised methods. Even if you use software tools that create those models, this book will help you understand how to use/test them correctly and how to avoid over-fitting.

Multiple examples are given in each chapter and most of the math is visually aided with graphs. The authors explain step by step any equation presented in the book. A notable example is how the authors show how the different parts of the Bayes’ Rule equation come together in chapter 9. There are also special Math-intensive sections that business managers might skip, but software developers and future data scientist need to examine closely.

I would recommend this book to any DBA or Developer looking for an useful introduction to Data Science. For a practical application of the concepts in the book, I recommend Data Analysis Using SQL and Excel by Gordon Linoff after reading Data Science for Business. As a SQL Server DBA, I will apply the concepts I learned with the book to SQL Server Analysis Services.

Saturday, November 02, 2013

How to make MS SQL integrated security work in Spoon

How to make Micorsoft SQL Server's integrated security (SSPI) work in Spoon:

  1. Download the MS SQL JDBC sql drivers
  2. Copy enu\auth\x64\sqljdbc_auth.dll to {spoon installtion folder}\libswt\win64
  3. Copy enu\auth\x64\sqljdbc_auth.dll  to {spoon installtion folder}\libswt\win32
  4. Copy C:\sqljdbc_4.0\enu\sqljdbc4.jar to {spoon installtion folder}\libext\JDBC
  5. Open Spoon
  6. When creating the data source, make sure to check "Use integrated authentication"

Please note that you are copying the 64 bit version of sqljdbc_auth.dll to both \libswt\win64 and \libswt\win32 if you have a 64 bit processor.

Tuesday, July 02, 2013

Alert if file missing using Powershell

The following Powershell script can be used to send an email alert when a file is missing from a folder or it is the same file from a previous check:

$path_mask = "yourfile_*.txt"
$previous_file_store = "lastfileread.txt"
$script_name = "File Check"

###### Functions ##########
Function EMailLog($subject, $message)
   $emailTo = ""
   $emailFrom = ""
   $smtp=new-object Net.Mail.SmtpClient($smtpServer)
   $smtp.Send($emailFrom, $emailTo, $subject, $message)

   #get files that match the mask
   $curr_file = dir $path_mask |  select name

   if ($curr_file.count -gt 0)
       #file found
       #check if the file is different from the previous file read
       $previous_file = Get-Content $previous_file_store
       $curr_file_name = $curr_file.Item(0).Name

       if ($previous_file.trim() -eq  $curr_file_name.trim())
           $msg = "Found same file as previous check: $previous_file and $curr_file_name"
           EMailLog "$script_name Error" $msg
           #different file, record its name for comparing in the next run
           $curr_file.Item(0).Name | out-file -filepath $previous_file_store

       $msg = "$path_mask Not found"
       EMailLog "$script_name Error" $msg
Catch [system.exception]
   "Caught a system exception "
   $error.Exception | EMailLog  "$script_name System error" $_

Saturday, April 06, 2013

Thoughts on how to prevent Abortions

I would like to first set the scope of this article; this is about abortions in cases where the couple had consensual sex and there is no life-or-death health risk to the pregnant mother. In regards to cases of rape or life-or-death risks to the mother, I think it is best for a panel of women (both pro-choice and pro-life) to discuss it. The panel should include people who have gone through those situations and who have taken either direction. No man (pro-choice or pro-life) should be included in that panel and meetings. I also want to clarify before we being that I am pro life in that I believe life begins as soon as the baby starts forming in the womb.

Having set the scope of this article, it is important to address the fact that it is very important to point out that when a baby is conceived, the couple is pregnant not just the mother. The responsibility falls to both the man and the woman. Paying child support is not even near the share of responsibility that the father should take on. It is sad that the justice system makes it seem that by just paying child support, the father is off the hook. The father should be forced by the justice system to have more responsibly such as baby sitting, spending sleepless nights, taking the child places and cleaning diapers. My suggestion is that if the father fails to comply with any of those, he should pay a fine and also be sterilize. This might sound like the government intruding on areas it should not, but I prefer that than having women abort their children because they will not have the support they need. By sterilizing the bad fathers, we as society can ensure that they won't be doing that to another woman.

Sterilizing procedures might sound a little bit extremist, but it can help curve spending on social welfare. I do believe in having some sort of safety net for poor children and poor elderly, however we as society need to be smart about it. Allowing people to have a large amount of children and then ask for welfare assistance sounds really dumb. People might disagree on how many children is too much for families assisted by the government. I suggest that two is enough. If a family has two or more children and they need welfare assistance  the government should sterilize the couple to prevent them from having more kids. This will free up more welfare resources for other children, like those with severe health challenges who might otherwise be aborted by couples who believe that abortion is a way to avoid the cost and time associated with taking care of a child challenged with severe health problems.

This bring another excuse people often use to justify abortion. Some people believe is OK to abort a child if the child is going to have severe health problems during his/her life. We don't often see (or even allow) parents to go their child dying of cancer and killing him/her to "spare" him/her from the pain. Many people who are born and live through sever health challenges do not commit suicide, which could mean that even if life is very tough there is either light at the end of the tunnel or there are some aspects in life that are worth living for. The same could be said about the "undesired" children, children who grew in families were they were not loved like they should. Many of them have had a terrible childhood life; but many of them are able to break away and find happiness even if it is at latter point in time or a reason to live for.

If couples are not willing to take care of their children if they are born with severe health problems, then I suggest they don't try to have babies on their own at all. There will always be risks with new babies and many parents are willing to receive their new babies as they are. If some couples are not willing to take that responsibility, then I suggest they sterile themselves to "spare" themselves from that risk. I then suggest they find an orphan toddler who looks healthy and adopt the child. I am not being sarcastic, I think this is a better solution than having the couple abort a child because the child happened to have some health problems.

Unplanned pregnancies can be avoided by abstinence or by using any kind of contraceptive. I truly believe abstinence works 100% of the time, but for people who do not believe in abstinence, contraceptives like condoms should be a no-brainier. There is no excuse for not using one. Thanks to movies, TV shows, schools, peers and the Internet, pretty much everybody knows what they are and how to use them. This responsibility should fall 100% on the man; no condom, no sex. If you are stupid enough to decide not to use them, please do society a favor and have a vasectomy (yes I am suggest this a lot, but it is very effective). Human kind does not need your stupidity genes in our Gene Pool, we have plenty enough.

If a couple do not have money to buy contraceptives, then they have bigger problems than trying to get contraceptives. Instead of spending time having sex, they probably should be spending all their spare time on finding ways of earning more money; like a second job or inventing something everybody needs. Sexual relationships are not unnecessary to human survival like food or medicines, so I do not support the government subsidizing contraceptives. We might as well subsidize video game consoles and music downloads. However, if it really comes down to either using tax money for contraceptives or aborting children, then please take my tax money and spare the babies.

The final excuse that I want to address is probably the most prominent. Women's right to choose what they want for their bodies. I do believe on individuals on having the right to do whatever they want o their bodies. If they want a tattoo or chop the ears, let them do it. Because of biological reasons, women are the ones who host the development of new humans beings in their bodies. Yes, nobody asked them, but that is just reality. So even though women do have the right to do anything they want to their body (arms, ears, liver,  lungs, etc), the new human baby developing in their womb is off-limits because anything damaging the baby inside is violating the baby's right to his/her body.

This brings another popular excuse: the baby is not really a person and is just a fetus and equivalent to a liver or to a kidney and therefore has no rights. The baby inside feels pain, moves, has a brain, has a palpitating heart, digests food and breaths. To me, that pretty much shows he is a human child. I really don't understand when people give this excuse since most of that same people would rightly fight tooth-and-nail to protect a child that is outside the womb. One of the excuses is that the baby inside the womb is completely dependent on his/her mother and therefore cannot be classified as a person. This argument is moot if you consider that newborn babies are also 100% dependent on another human being for protection and for food and they are classified as persons. I honestly do not see the difference between a newborn outside the womb and a child developing inside his/her mother. They are both humans and they both depend on their mothers to survive. They should have the same rights, including the most important one: the right to life.

Monday, April 01, 2013

How to easily import data from SQL Server into PostgreSQL

I was looking for an ETL software similar to SSIS that would allow me to easily move data from SQL Server to PostgreSQL. I tried using SSIS, but I was never able to make BIDS generated the schema of the destination table automatically like it would do with a SQL server destination table.
I downloaded Pentaho’s Spoon data integrator and it surpised how easy it was to do it there. The designer is somewhat similar to BIDS. You drop your input tables (from SQL Server) and then you drop your destination tables (PostgreSQL tables).
The good thing is that you do not need to create the tables in PostgreSQL beforehand. You just need to create the destination database. When you open the properties of the Table Output, you can enter the name of the new table and then do the following to create the table based on the data input:

  1. Click “Database Fields”
  2. Click “SQL”
  3. Click “Execute”

That’s it. Your table will be created in PostgreSQL using the correct data types.
Pentaho’s Spoon data integrator also have other nice features, such as Json input/output, Google Analytics input, Hadoop and SalesForce connectors, and more. The software is free and can be found at