Unity 3D UI Position Instability (shaky UI)

I recently experienced an issue where I noticed that many of my UI elements would be shaking (unstable position) while the camera is in motion.

The setup I had was that described by Unity at one of their Unite conferences for performance (ie. logically nesting canvases under one canvas as much as possible). The canvas had pixel perfect turned off explicitly and the plane distance was 1, which was lower than the default 100 when you add the canvas using the create menu. The root canvas was set to a render mode of “Screen Space – Camera”.

After a few methods of troubleshooting I finally realized that this was caused by the plane distance being set to a low value while using a render mode of “Screen Space – Camera”; if I returned the plane distance value back to the default 100 there is no problem! Ensure that this is the option that suites your needs the best as “Screen Space – Overlay” might be a better choice in many cases. If you do need to use “Screen Space – Camera” in your situation then you would want to try out some values on different screen resolutions and platforms to ascertain that your users will not experience this behavior.

There is an “Screen Space – Overlay” option for root canvases which would be a better option in most scenarios. It does have some impact on FPS but it eliminate this “shaking” UI problem as well as any potential issue related to the UI not being visible due to obstruction by a closer mesh.

ConciseXMLParser Java Library

I was happy to have my first opportunity at delivering an open-source project for the use of everyone. This project is available here and has been uploaded into Sonatype’s Central Maven Repository.

Isn’t there already XML Parsers for Java?

It may seem weird as there are already many XML parser out there for Java. Actually I was using XML in an odd scenario and could not find a solution suitable to my needs after a few hours of searching.
I noticed that many libraries that were available were verbose and I wanted to minimize the number of lines required to load the XML file content. I also needed it to be able to accommodate XML that is not intended to represent structured data (objects with the same attributes) but rather I needed it to be able to handle the unstructured data that can be found in an application configuration file.
Oddly, after completing the library I did read about a Java Library called XPath and also read that the same solution was not geared toward performance consideration.

Why not write a Java properties file?

One of the considerations I had is if I needed to move the config in the future I would rather have it as an XML as parsers would be available for many programming languages.
Another is that the properties file can become really difficult to read and maintain if your intention is to logically nest objects within others. Imagine having to read keys like:

cows.cow.bettie.length

Now try nesting a few more times to see the point.

What is it about?

The project basically is geared towards reading an entire XML file and providing it as key->value pairs in a HashMap. In order to accomplish this, a few assumptions had to be made in order for the library to work effectively.
The readme in GitHub explains what these assumptions are as well as the rules used for generating the keys for each value.

Certbot Quickguide

Creating Certificate

certbot certonly  -w /var/www/example/ -d www.example.com -d example.com -w /var/www/other -d other.example.net -d another.other.example.net

Renewing Certificates

Certificates generated using certbot last 90 days. Following command attempts to renew all certificates managed by certbot.

certbot renew

Following command does a test renewal (ie. doesn’t keep new certificates and old one still works).

certbot renew –dry-run

Revoking Certificate

certbot revoke -d abc.example.com –cert-path /etc/letsencrypt/live/example.com/cert.pem

References

https://certbot.eff.org/#ubuntuxenial-nginx

NGINX fails to ask for PEM password on start

Build

  • Ubuntu 16
  • nginx version: nginx/1.10.0 (Ubuntu)

Problem
Amongst the common commands you will find online to start Nginx are:

Using a service
sudo systemctl restart nginx

Call the binary directly (assuming it located in /etc/init.d/) with start/stop/restart
/etc/init.d/nginx start

Even if you specify the configuration file using the -c option, it always throws an error.

However, it appears (for me) that neither of these options prompt a user for their PEM password if they have configured SSL or TLS certificates.

Solution
After a lot of digging you will find that calling the script directly without (start/stop/restart) prompts the user for the PEM password.
/etc/init.d/nginx

References
https://forum.nginx.org/read.php?2,262900,262900

Autosize Images in Android

Problem
Images were displaying in a way that was not desired, by default. Many times we want images to display with the same width and height while maintaining the aspect ratio of the image. Typically we also want to be able to see our images have consistent widths and heights, especially when working with tiles or lists.

Solution
I paste the basic layout of one of my adapters to illustrate.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/row_parent"
    android:orientation="horizontal"
    android:padding="10dp"
    android:weightSum="4">

    <FrameLayout
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="match_parent">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="fitCenter"
            android:id="@+id/img_profile"
            android:adjustViewBounds="true"/>
    </FrameLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="0dp"
        android:layout_weight="3"
        android:layout_height="match_parent"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:id="@+id/container_profile_summary">

        <TextView
            android:text="TextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/lbl_name" />

        <TextView
            android:text="TextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/lbl_occupation" />
    </LinearLayout>

</LinearLayout>
android:scaleType="fitCenter"

This will apply ScaleType.FIT_CENTER which as the documentation states

Scale the image using CENTER.

CENTER as the documentation states will

Compute a scale that will maintain the original src aspect ratio, but will also ensure that src fits entirely inside dst. At least one axis (X or Y) will fit exactly. The result is centered inside dst.

android:adjustViewBounds="true"

This attribute is important and required. Android says about this attribute

Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable.

I had issues making the ImageView work when I’m applying the scaling and using weights, so I put it as a child of a FrameLayout and found it to work successfully.

References

Using Eclipse EGit Plugin to Push Changes to Remote

Introduction

This guide was intended towards my ILP group working on adding features to an old java game made previously.

Assumptions

This guide assumes you have already cloned and made changes to indexed files in the project.

I am also assuming that there is only one branch, namely the master branch.

Step 1

Right Click on your project in the package explorer > Team > Commit…

Step 1

Step 2

Add the files you would like to apply to the remote repository to the staged changes section, shown below.

Right Click on the File > Add to Index

egit-2

Step 3

Enter a commit message.

Enter your author (if necessary).

Click “Commit”

egit-3

Step 4

At this point, if you have other members working on the same branch, you will want to retrieve updates that happened between the time you started making changes in the project and the time you committed those changes.

egit-4

Step 5

You may or may not have to deal with conflicts from other commits. I have not come across this situation yet so I can’t show an example here at this time.

Step 6

After handling conflicts. You want to push your changes to the remote Git repository.

Right Cick on Project > Team > Remote > Push…

NOTE: This is NOT the same as Team > Push Branch ‘master’ or Push to Upstream

egit-5

 

Glassfish Error – java.lang.ClassCastException: org.glassfish.grizzly.config.ContextRootInfo cannot be cast to org.apache.catalina.Context

This error appeared for me because I set a default web module previously to a different enterprise application archive (ear) project while trying to run a new one in the development environment.

The solution for me was to empty the Default Web Module field shown below and restart the server. After you do that you can deploy your application successfully.

Glassfish Configuration

Create New MySQL User and set Privileges

Introduction

This guide will show you how to make a new user and assign them all privileges to a specified database.

This is not a unique tutorial but is mainly intended as a quick reference for the author. Hope you find it useful though!

Steps

Create new database user along with their password. This will apply to all databases they access.

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

Give user all privileges to a particular database

GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';

Necessary to apply the changes.

FLUSH PRIVILEGES;

References

https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql

Redirect from HTTP to HTTPS on Glassfish

Introduction
This tutorial is intended to show you how you can force various url patterns to use HTTPS if a user tries to use HTTP.

Build

  • Glassfish 4.1
  • Netbeans 8.1 (Not necessary, will have instruction for both)
  • JavaEE 7 (Don’t think its necessary)

Instructions
Navigate to your Web Application Archive’s (WAR’s) web.xml file.

Method 1: Netbeans

NB Step 1

NB Step 2

Method 2: Good ol’ Copy n’ Paste

The above steps would have created the following code which you would add into your file. I apologize it would not save the spaces.

<web-app>

<security-constraint>
<display-name>Constraint1</display-name>
<web-resource-collection>
<web-resource-name>Anything</web-resource-name>
<description>This will make the constraint affect all pages of the application</description>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<description/>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>

</web-app>

References

Set context-root of Application running on Glassfish as the Domain Base

Introduction

Whether you want to set your ear, war or whatever type of application up on Glassfish, we typically want to get rid of the default landing page and replace it with one of the apps. This guide will show you how, with one image. This method is the easiest but has a caveat which I will mention later. It should work in Glassfish 3 and beyond, at the least.

Build

  • Glassfish 4.1
  • Using an Enterprise Application Archive (EAR)

Assumptions

  • Name of configuration and virtual server are default

Instructions

  1. Deploy your application
  2. Navigate to Configurations > server-config > Virtual Servers > server
  3. Select desired application on Default Web Module
  4. Save

Instruction Image

Caveat
If you specified in the configurations of your file a different context root (file depends on what type of application) then you will be able to access the application from the Domain Base as well as the context root defined in the application’s configuration file.