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 http://www.pentaho.com/explore/pentaho-data-integration

Friday, November 02, 2012

Authenticate OpenXava users with ActiveDirectory

The following allows you to use JNDIRealm's LDAP authentication to authenticate users of OpenXava application with Active Directory. The users will be prompt to enter their windows credentials, when entering the usernames they need to avoid entering the domain name; they just need to enter the username.

If you have multiple Active Directory domains to authenticate against, you can use  org.apache.catalina.realm.CombinedRealm to allow Tomcat to search on both.

In the web.xml you will need to specify the security-constraint setting. This will force the user to authenticate when they reach any OpenXava module. in role-name, you have to enter the Windows Group name of that is allow to access the application. If you need finer restrictions, you can use OpenXava's Users.getCurrent() to get the username of the current user in your Java code. For example, you could have a validation logic to prevent a certain user from creating a new record.

Please note that you must use a security-constraint setting in web.xml in order to use Users.getCurrent() in your Java code.

web.xml in app folder

<security-constraint>
<display-name>Example Security Constraint</display-name>
<web-resource-collection>
  <web-resource-name>Protected Area</web-resource-name>
  <!-- Define the context-relative URL(s) to be protected -->
  <url-pattern>/modules/*</url-pattern>
  <!-- If you list http methods, only those methods are protected -->
  <http-method>DELETE</http-method>
  <http-method>GET</http-method>
  <http-method>POST</http-method>
  <http-method>PUT</http-method>
</web-resource-collection>
<auth-constraint>
  <role-name>THE NAME OF A WINDOWS GROUP (NO NEED TO SPECIFY DOMAIN NAME)</role-name>
</auth-constraint>
</security-constraint>

<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Windows Login</realm-name>
</login-config>
<security-role>
    <role-name>THE NAME OF A WINDOWS GROUP (NO NEED TO SPECIFY DOMAIN NAME)</role-name>
</security-role> 

In the server.xml file, you need to add the JNDIRealm that will allow Tomcat to connect to Active Directory via LDAP. The example below uses the CombinedRealm class to combine two Active Directory domains.

server.xml in tomcat's conf folder


<!-- make sure to remove the existing realms –>
  <Realm className="org.apache.catalina.realm.CombinedRealm" >
<Realm
        className="org.apache.catalina.realm.JNDIRealm"
        debug="99"
        connectionURL="ldap://DOMAIN-CONTROLLER-NAME.YOUDOMAIN.local:389"
        connectionName="SOMEUSER@YOUDOMAIN.local"
        connectionPassword="YOURPASSWORD"
        referrals="follow"
        userBase="DC=YOUDOMAIN,DC=local"
        userSearch="(sAMAccountName={0})"
        userSubtree="true"
        roleBase="DC=YOUDOMAIN,DC=local"
        roleName="cn"
        roleSearch="(member={0})"
        roleSubtree="true"/>
       
   <Realm
        className="org.apache.catalina.realm.JNDIRealm"
        debug="99"
        connectionURL="ldap://OTHERSERVER.YOUSECONDDOMAIN.LOCAL:389"
        connectionName="SOMEUSER@YOUDOMAIN.local"
        connectionPassword="YOURPASSWORD"
        referrals="follow"
        userBase="DC=YOUSECONDDOMAIN,DC=local"
        userSearch="(sAMAccountName={0})"
        userSubtree="true"
        roleBase="DC=YOUSECONDDOMAIN,DC=local"
        roleName="cn"
        roleSearch="(member={0})"
        roleSubtree="true"/>
       
 
</Realm>

In your OpenXava java code, you can obtain the username (no domain name) of the user visiting the page by calling Users.getCurrent(). The Users class lives in the org.openxava.util package

This approach works inside of a secure Intranet, hence the sending of credentials in plain text (BASIC in auth-method). To improve security, please configure Tomcat to use HTTPS only.

You can use a similar configuration to allow other Java web based application to authenticate users with Active Directory. You would probably have to modify the web.xml of the app and use the same server.xml configuration shown here.

Sunday, July 29, 2012

A Solution to the Marriage Dilemma


In the midst of the raging battle between those who want to legalize homosexual marriages and those who oppose it, a solution could be implemented that would fit the goals of both sides. The problem with the traditional marriage constitutional amendment is that it asks the Government for the wrong thing. Asking the Government to define marriage as one man and one woman is a huge mistake because it takes away that power from religion and puts that power in a Government that is already taking too much power. It is extremely important for the survival of the Church that the government stays away from her.

If we let the Government take that power,  not only would break the first amendment, but it also would teach future Christians generations that it does not matter what the Bible says what marriage is, all it matters is what the Government says it is. The definition of marriage belongs to culture and religion and it should stay there. Instead, I would like to propose the following: have the government erase the word and concept of marriage from all it's laws and prevent it from making any law that refers or affects marriage. There are two obstacles to this solution, however.

The first obstacle is that there are already some laws regarding taxes, possessions and power of attorneys that are based on "marriage". Overcoming this obstacle is simple: have the government create a special type of corporation (e.g. : corporation Z) that would give individuals the same rights and responsibilities a married couples. Just like any other type of corporation, anybody and any number of people can file for it. Christians would file one with their spouses, Mormons who believe in polygamy would file one with all their wives under it, homosexuals would form one with their partners.this would work great because at the end of the day, The  government currently treats families a lot like corporations except that families don't get bailouts. Currently anybody can create a corporation so it would satisfy the requirement of everybody having the same rights given by the government. By issuing corporations instead of marriages, the government would then stay away from the power that should remain in religion and culture.

The second obstacle is that currently, religious leaders have a power from the State to declare a couple husband and wife in the eyes of the Government. We need to dissolve this dangerous relationship for two reasons: first, it allows the State to tell religious leaders who can marry and second, the power to declare somebody husband and wife comes from God not from a filthy government. It would work something like this: If a Christian couple want to marry before God, then they would go to a preacher who would deem if they are ready or not to marry before God. By breaking the ties with the state, the preacher would be free to use his judgement to officiate the marriage or not. if the couple want to get the rights and responsibilities given by the Goverment, then they would file online (to keep it cheap) to form a corporation. The key is to keep the process separated so that the Government does not stomp over religion. By having no laws regarding marriage, churches would be free to refuse to marry anybody that behave not in accordance to their beliefs.

So, does that mean that an homosexual couple would be able to file a corporation and go to a church that allows gay marriage and have a "marriage"? Yes, it would allow them to do that. And that is fine in a political perspective and a Christian perspective. In a political perspective, that couple has the right to have a religious ceremony that agrees with their beliefs. On a Christian perspective, that marriage is simply not valid and we would know is not valid. As Christians, it would also give us an urgency to reach the lost and to work on our own marriages to make them an example to others. 

Some people say that "gay marriages" would destroy families. Although I believe that the Bible says that Homosexuality is a sin (just like lying, watching pornography, having sex before marriage, getting drunk, etc.), I believe that biggest treats to family are infidelity, abuse, uncontrolled finances and vices like drunkenness and drugs. Those are the bigger fishes we need to fry, but unfortunately a lot of Christians have those problems at home, and the sad thing is that the World knows it too.

The above (and everything in this blog) is solely my opinion and does not necessarily reflect the opinions of my family, my current or previous employers, or my current or previous Churches.

Tuesday, May 01, 2012

Construct2: surpassing GameMaker and Multimedia Fusion

I a few years ago, I posted an article about why I preferred GameMaker over Multimedia Fusion. A lot has happened since then, Clickteam released many exporters for MMF (Flash, IOS and others) and YoYo Games have made HTML5 gaming GameMaker’s new target. Another product has been in the works too, Scirra produced Construct2 as a HTML5 game maker. Just like I reached my conclusion back then through spending time on GameMaker, I have come to the conclusion that Scirra’s Construct2 is a very worthy contender to both by spending some time using it and writing plugins for it.

Construct2’s main target is HTML5 gaming, however, it is straight forward to create exporters for it and I am actually working on a XNA exporter for it. I have also created plugins that allow Construct2 games to create simple 3D games (WebGL via Copperlicht), online multiplayer games (through websockets) and isometric games (through a Z sorter plugin).

 imageimage

Construct2 enjoys an easy-to-use event-driven interface similar to MMF’s. However, you can take full advantage of the engine by writing plugins in Javascript. The plugin system in Construct2 is one of the easiest I have ever worked with. Any programmer can write plugins for it, the dozens of useful plugins created by the community being proof of that.

image

The plugin system allows experienced programmers to design their game code in a clean way using separation of concerns (which they should be doing in the first place). You can write your heavy custom logic into plugins and use the event editor to glue the plugins together. If you are just a beginner, you can use the many built in plugins and behaviors (8 dir movement, car movement, physics, Facebook, platform movement, particle system, etc.) or use the many plugins made by the community.

Construct2’s HTML5 game engine is currently faster than GameMaker’s in canvas mode. Construct2 also allows you to use webgl in your game and that makes your game graphics even faster.

It will be exciting to see how MMF and GameMaker will react to the many features that Construct2 brings to the world of beginner’s game making.

Thursday, April 19, 2012

How to create online multiplayer HTML5 games in Contruct2

 

Construct2 can use websockets to send and receive messages between games. By using socket-io, we can use a Node.js script as the server and my modification to the socket-io plugin for Construct2 to allow the games to synchronize data between them in real-time. There are two parts to this design: the Node.js server and the Construct2 clients (the games playing).

The main part of building an online multiplayer HTML5 game is to plan:

  1. how the clients will communicate
  2. how often and what to communicate
  3. how much of the logic will go into the server and how much to the client.

In my sample game, I chose to have each client own a player and have the server just relay messages:

  1. Use string messages in the form TypeOfMessage, Parameter1, Paremeter2, Parater3, etc to communicate.
  2. Have the clients send their player position about 16 times a second. Whenever their player shoots, the client needs to send a message immediately.
  3. Almost all of the game logic will reside in the client

The Server Script

The server runs in Node.js and functions as basically a relay of messages between Construct2 clients. The server needs to run outside of Construct2 because a construct2 game cannot run as a server, i.e. it cannot use your computer to “listen” to messages. It can only connect to a websocket server (in this case Node.js) and sent/receive messages to/from it.

If you look at the source code of the example_server.js file included in my plugin, you will see that the first thing we do is to listen in port 8099:

var io = require("socket.io").listen(8099);

The next thing we do is to staet listing for connections, and if we get one, we send the connecting client an initialization message:

socket.send('I,' + mySelf[0] + ',' + mySelf[1] + ',' + mySelf[2]);

The initialization message simply tells the connecting client (the C2 game) the id of his player and the initial x and y coordinates for his player. Note that the message is just a string. I chose to make my messages sent from the server formatted in the following way:

TypeOfMessage, Parameter1, Paremeter2, Parater3, etc

The parts of the message are separated by commas. Next in the server script, we use a loop to send the connecting client the positions of each of the clients (players) already connected:

socket.send('C,' + entity[0] + ',' + entity[1] + ',' + entity[2]);

This message type is C, which means that the client has to Create a player (in this case the other clients have to create the new player that just connected). We will see later how the Constrcut2 clients interpret those messages. After the positions of the players are sent to the connecting client, we broadcast the to the clients already connected that a new client has arrived and its id and initial position (which was set by this script):

socket.broadcast.emit("message",'C,' + mySelf[0] + ',' + mySelf[1] + ',' + mySelf[2]);

Please note that the initial position is set by the server to the same position always for simplicity, however, in your game, there is no reason why you have to do this. You could have multiple random spots and just let the server assign any of those random spots.

The next part of the server script uses socket.on("message", function (data) to start listening to any messages sent by this newly connected client. This line is different from the previous io.sockets.on("connection", function (socket) in that the later line listens to connections only not messages.

Each message sent by the client can be a UM (update position) or a S message (shoot). The server splits by comma any message sent by the client, detects what kind of message is and then relays the message to all the other clients (players). Note that if th message is a UM (update position), the server will save the position so that it can send the correct position to any new client.

The Client

Each client is a Construct2 game that use the modified websocket plugin to send messages to the server (not to the other clients).

On the start of the playing layout, we connect to the Node.js server using its IP address:

image

Note that the IP address could be public or a LAN address. If public, the server (node.js) must be running in a LAN whose router redirects the 8099 to the computer running the Node.js server script.

Once connected, the client listens to messages from the server. The first message it will receive is an Initialization message:

image 

When this message arrives, C2 will create a player in the coordinates given by the server and assign the owned player the id sent by the server. Note that plugin has a special action “Split Data Received” that splits the message into its parts (element 0 is the type of message, element 1 is the ID of the player, element 2 and 3 are the X and Y positions).

The client will also receive C messages to create the other players:

image

Finally, the client will receive messages to update the position of the other players or to have the other players shoot:

image

To update the position of the own player and to notify the shooting of the own player, the Construct2 game will send messages to the Node.js server when the conditions occur:

image 

Note that it sends its player position every 0.07 seconds. Whenever their player shoots, the client also sends a message immediately.

Summary

Document_2012-04-19_11-10-04

The above picture give you a quick overview of how the parts discussed interact with each other. Please remember that you can make your message represent anything you want, e.g.: player picks up an item, player dies, etc. However keep in mind that you should limit the amount of information flowing. Choose the most basic messages that would allow your game to run parallel. For example in my sample game, I do not have a “Died” message because I am trusting that the clients are synchronized enough that if a bullet hits a player in one client, the same bullet will hit it in the other client because the bullet was created with the same position and velocity in all the clients.

There are some tips here on how to install Node.js and socket-io in your machine.

Online multiplayer takes a lot of discipline and knowledge. I strongly recommend that you start with something basic (like a pong game where you just update positions) and then move from there.

Monday, March 19, 2012

Prevent Visual Studio from using SQLEXPRESS when using Webparts

To prevent Visual Studio from using SQLEXPRESS when using Webparts and WebPartManger, you will need to override the "LocalSqlServer" connection string from your machine.config into your web.config file. To do that, add the following to the <connectionstrings> sections in your webconfig file:


<remove name="LocalSqlServer">
 <add connectionstring="data source=.\YOURINSTANCENAME;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" name="LocalSqlServer" providername="System.Data.SqlClient">
</add>


Othwerise, if you do not have an instance named SQLEXPRESS in your machine, the page containing your WebPartManager will fail with the following error:


A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)