This post pertains to React Native v0.12.0-rc.

I am attempting to port my iOS app in react-native to Android. I am experiencing a bunch of issues surrounding colors and default styles. I am getting TypeError: expected dynamic type ‘string’, but had type ‘int64’.

Attached the debugger to the processes and I am seeing calls to the following code in CatalystStylesDiffMap.class:

Examining the values I see the color property is an int64.

As it turns out the Android project and the node-module for react-native were out of sync and this caused lots of problem with regard to style color properties.

It looks like my application (even when initing a fresh app) was importing java libraries for 0.11 dependencies:

I verified my installed version of react-native

init’ed a new project and looked at the build.gradle file to see it is 0.11+.

Checked the node_modules/react-native/Libraries/StyleSheet to see 0.11 files (0.12+ has a new processColor.js file in it as seen by recent commits.)

So to make this work I changed the build.gradle to 0.12+, and ran npm i react-native@0.12.0-rc to force the correct android libraries and the correct react-native module. Now the app works.

Is this my machine or npm cache that is horked up or is it an npm install problem with the 0.12.0-rc? I also noticed that none of the files in the $PROJECTDIR$/android folder get updated when doing an npm i or npm update which leaves the native app setting behind in version.

There are lots of tools that compare two PostgreSQL databases.  Most are command line and the precious few that are UI based either cost too much money (from an independent developer’s perspective).  So like any persistent developer I decided to write my own and learn about Electron along the way.

I open sourced the tool so anyone can use it for free.  My intent is to provide the schema compare functionality for free forever.

The shell container for the application is my first foray into Electron which uses io.js and Chrome browser to power the desktop application.  The UI is presented as HTML and the HTML side of things is using AngularJS and Bootstrap to make the nifty UI. It’s a pretty cool concept and supports Linux / Mac OS X / Windows.  I will provide binaries as well in the near future.

Here is a link to the homepage.

And here is the link to the Github project site, please feel free to submit pull requests!

screen-01 screen-02 screen-03

 

As of the latest version of pm2 there is a slight bug in the process that writes the startup script to your /etc/init.d directory.  Out of the box the on reboot (or by executing the script as root) you will see the following error:

The fix is simple.  By fixing one line of code in the shell script your pm2 will now startup correctly.

Note the export PM2_HOME line is incorrect.  The PM2_HOME should actually point to the home directory of the USER you told pm2 to run under.  So change that line to the following:

Note that myPm2User should be replaced with whatever user account you want to run pm2 under.

Now when you reboot you will see success:

 

 

 

I screamed at the computer today while looking for examples of how to properly use the whereArgs argument of the SQLiteDatabase.delete() function.  I am pretty sure I puked a little when I read this horrible advice on Stack Overflow:

I am having flashbacks to 1996 when this first became an issue for developers (yikes, showing my age).

The correct way to do this is to use the whereClause and whereArgs arguments to prevent SQL Injection.

Here is the documentation for the method (although it is lacking good guidance).

So correct code would look like this:

 

There are a few links on Stack Overflow about this topic but the solutions seem old (link, link).  I figured out how to do this correctly in the latest version of AngularJS (v1.4.0 as of writing this).

Then add the interceptor to the pipeline like this in your App.run function.

As a side note, I left my session injection code in there.  I use this to insert a sessionid header into every request.  You can remove that part and rename this interceptor from sessionInjector to unauthorizedToLoginInterceptor if you wish.

TL;DR – Use SELECT * FROM functionName(); vs SELECT functionName();

Given the following custom data type in PG:

I created a simple function that selects the correct counts to fill this data type correctly and then returns the data type as a result.

So there are a few ways to use this function.  The first IMHO is useless:

Which results in the following result:

Screen Shot 2015-04-18 at 6.26.16 PM

However querying the following way results in a more useful response:

Which give a useful response:

Screen Shot 2015-04-18 at 6.27.59 PM

First connect to the PG server using psql and as your DB owner account or the superuser account.

$> psql

Create the user and set a password.  Here I am creating user rouser with a password of R34D0NLY.

CREATE ROLE rouser WITH ENCRYPTED PASSWORD 'R34D0NLY';

Next, switch to your database context (here my database is named mydatabase, and my superuser is named postgres)

postgres=# \connect mydatabase;

The prompt will switch to:

mydatabase=#

No execute the following (be sure to swap out your username with my rouser username):

Now your user has readonly access to the schema public.  If you are creating tables and other database objects in another schema you will need to do the same thing but replace public with your other schema name.

Allow a user to use a sequence:

 

I have been using JetBrains new 0XDBE to do some database development on PostgreSQL.  I installed PostgreSQL myself on my linux VPS and immediately got frustrated with the following error:

java.sql.SQLException: SSL error: sun.security.validator.ValidatorException: PKIK path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target.

Seriously?

Data Sources and Drivers

 

The error is confusing but luckily the fix is simple.

In the Data Source settings add: org.postgresql.ssl.NonValidatingFactory to the sslfactory setting in the Advanced tab.

settings

 

After adding that setting click apply and then test the connection again and you should be good to go.

success

 

Working on an Android application at the moment and needed a quick way to make calls to a REST api.  I found Luke’s post very helpful.

There were some quote corruptions and a missing enum so I fixed those and provided a zip file for the class.  This is NOT MY WORK, please thank Luke for his work 5 years ago.

RestClient.java

UPDATE: I added the ability to do basic auth with this class and the ability to attach a JSON object to the request.  In my opinion it makes this class a lot more useful.

 

 

This video will show you how to show a new view from a tab in a tabbed application and properly dismiss the new view.

Here is the full source code for the example I provided above: Tabbed View Segue Example

Screen Shot 2014-10-11 at 2.47.37 PM

Start by adding a button to one of the tab views.  I added a button to my First View.

Screen Shot 2014-10-11 at 2.54.38 PM

Next, drag a view controller onto the storyboard.  Add a label to it just so you know that the correct view actually loaded.  Then add a button to the upper right corner of the view and give it the text Done.  This Done button is going to be used to dismiss the new view and return to the original tab view that launched the new view.

Now we need to add a swift view controller code file to the project so that we can wire up the Done button and have the view controller dismiss when we click that button.

Just add a new swift file to the project.  I called mine MySecondViewController (sorry I chose a poor name for this view controller when I was recording the demo).

segue_swift_file

 

Add the boilerplate code and also add the new DoneAction function.

Now that you have this new view controller class we need to assign it to the new view that we created.  You do this by clicking on the yellow View Controller button on the view and then choosing your new view controller class in the Custom Class drop down.

link view controller to custom view controller code

Now we need to connect the View 2 button from the first view tab view to the new view.  You do this by Control clicking on the button and dragging the mouse over to to the new view.  As you see in the screenshot below you will see a blue line.  

CreateSegue

When you let go of the mouse button you will get a Segue menu.

SegueMenu

 

On the Segue menu you click the show option.  This will create a Segue that shows the view that you connected the button to.

wire up button to ibaction

You now have to wire up the Done button to the @IBAction we created earlier so that clicking that done button will actually dismiss the view.  The easiest way to do this is to click the assistant view (see arrow in the above screenshot) and then control drag the button to the IBAction and let go.  This links the button to the code in the custom view controller.

Run your application now and you will see that clicking the button on the first view will segue to the new view and clicking the Done button will properly dismiss the new view.

At the end of the video I show you how to use Instruments in order to see that by dismissing the view controller memory is freed up.  If you were to create a segue from the new view back to the first tab you would create a memory leak because you would be infinitely creating new views and displaying them.