One of the best ways to learn is from well-done examples. That’s not quite easy, when you’re up to Ionic 2, Angular 2 and TypeScript. These are state-of-the-art technologies, whose final release are imminent within days, but yet to come.
Most of the few apps you’ll find googling for Ionic 2 example either are trivial or they suffer from various defects.
Here is an Ionic 2 example app that immediately shows its mastership, both when sampling its appearance and when inspecting its code. This does not come as a surprise, as its creators are indeed the masters of Ionic themselves. What most impresses me, is that it works out-of-the box as a web site. Little remains to be done to turn it into a true Progressive Web App.
This is not a “real” app. Its contents are fictitious, there is no backend and it’s a work in progress. It just shows how to build a well designed Ionic 2 application.
You’ll find the sources and docs at https://github.com/driftyco/ionic-conference-app. Do poke around this repo to find many other Ionic 2 examples.
Have a sneak peek at what it looks like at https://service.saddey.net/ionic-conference-app/index.html (master branch as of 20-aug-16).
I want to create a simple Progressive Web Application (PWA) user registration dialog, which runs on mobile devices, accepts user data and saves them to some backend.
I chose Ionic 2 (ignoring its capabilities to create native apps), because it’s based on Angular 2. It’s like sliced bread. And it uses TypeScript as its (preferred) language. If you’re new to Angular (as I am), head over to Code School’s Accellerating through Angular 2.
Before installing Ionic 2, you’ll need Node.js because it’s required by Ionic 2.
Refusing to infect my MacBook with all sorts of beginner’s (and beta) garbage, I chose to confine my developer environment within a Docker container, avoiding both homebrew and the irreversible native installer as well.
This will give you a virtual environment to take with you, hand over to colleagues, or even publish for anyone to start using within a couple of minutes.
I do love Transmit for its smart Finder integration, e.g. mounting remote hosts as “disks” within Finder or quickly opening connections saved as droplets directly from Spotlight.
But… I was quite shocked to find it takes Transmit 10 times longer than Cyberduck to transfer text files when using SFTP – 2 minutes instead of 12 seconds for a 20+ MB server.log via a 2 Mbit line (I know it’s slow, it’s not mine…) 😡
It took some time of fiddling to uncover Transmit uses OS X standard ssh configuration settings as defined within ~/.ssh/config or /etc/ssh/ssh_config.
Thus I created ~/.ssh/config containing
et voilà, Transmit now compresses files on-the-fly as well 😀
This mail showed up this afternoon within my inbox:
Dear REINER SADDEY,
Your volume experienced a failure due to multiple failures of the underlying hardware components and we were unable to recover it.
Although EBS volumes are designed for reliability, backed by multiple physical drives, we are still exposed to durability risks caused by concurrent hardware failures of multiple components, before our systems are able to restore the redundancy. We publish our durability expectations on the EBS detail page here (http://aws.amazon.com/ebs).
While it might raise your pulse, it didn’t raise mine: It’s now been just two weeks after having set up an Amazon EC2 instance – for the very first time in my life and mainly just for wetting my feet. 72 instance hours in total.
I thus considered the failure both an important warning and a welcome opportunity to practice how to restore an EBS based EC2 instance.
Starting to google for this particular task, I soon suspected it to be a c(o)urse of frustration: From next-to-impossible to contradicting statements and stories (you must create an Ami, no, you have to launch a new instance, this only works for Linux, a.s.o.), anything can be found, but no definite, convincing and authoritative recipe for restoring a Windows EC2 instance from a snapshot.
After having made up my mind to abandon further outside help, I chose to proceed exactly as I would like a restore to be performed in the first place. This is what worked for me targeting a single volume (boot-only) instance:
- Detached the failing volume from the EC2 instance
- Deleted the failing volume
- Created a new volume (within the same availability zone as my EC2 instance) from my snapshot
- Attached this volume to the EC2 instance using device name /dev/sda1
- Started the instance
- Retrieved my Administrator password (the cryptic one, must have changed it after taking the snapshot)
After having logged-in using RDP, I found all and everything exactly the same as at the time the snapshot was taken🙂
When porting your Grails application from just about any database to MS SQL Server, four areas come to my mind that require your immediate attention:
- Primary key generation strategy (not covered here)
- Case sensitivity and collation issues (not covered here)
- Storage and retrieval of Unicode data (not covered here)
- Handling of unique constraints on columns that allow nulls
With MS SQL Server you’ll notice your unique constraints defined within Grails domain classes may no longer work as expected if null values are allowed (either explicitly or when using table per hierarchy inheritance).
Today I’ll present a work-around for MS SQL Server 2008 that does not require any manual intervention.
When using unique clauses within the constraints sections of your domain classes, Grails will do both:
- Perform lookups on every insert or update in order to be able to create meaningful messages within the errors collection, and
- by virtue of Hibernate hbm2ddl, create unique constraints within your database to enforce uniqueness even when validation is bypassed.
What’s so special about MS SQL Server?
Microsoft SQL Server has always been special when it comes to null values. There are several options (suspiciously named ANSI_xxx) controlling the handling of null values, e.g. whether null = null yields true a.s.o., but all those fail to take any effect on unique constraints.
With Microsoft SQL Server unique constraints treat null values just as if they were ordinary values – a uniquely constrained column does at most allow for a single row to have the value null. This appears to be in violation of ANSI SQL standards and there are (as yet futile) requests to (optionally) alter MS SQL Server behavior.
Depending on your business rules, not-null properties (e.g. nullable:false, blank:false, unique:true) may be appropriate. But watch out for object inheritance when using table-per-hierarchy mapping (Grails default). As a single table is used to store different kinds of objects, a property defined as nullable:false within a sub class must be mapped to a nullable table column as other sub classes do not share this property (i.e. they have no value for this particular column at all). And if such a property has been constrained by unique:true, your application is bound to fail with SQL Server, as it will at most allow a single row where the value of this property is null.
There are several work-arounds in the wild, most of them exceedingly awkward to handle and maintain – with one notable exception: Starting with MS SQL Server 2008 indexes can be filtered, i.e. a (simple) where clause can be applied to the definition of an index. Thus a unique index that ignores null values can be used in place of a unique constraint to enforce uniqueness of non-null values.
What you’ll need to run or use the Grails MsSqlConstraints project sample code
- The Grails demo project MsSqlConstraints.zip.
- MS SQL Server 2008 (express edition will do, I used 2008 R2) allowing SQL Server authentication (i.e. user and password). The demo project accesses a database named demo at your local SQL Server using demo for both login and password. Best to have a look at DataSource.groovy first.
- Grails 1.3.7
- Java 6 – Java 6 Update 29 has a bug that prevents it to connect to MS SQL Server 2008 R2. Either upgrade to Java 6 Update 30 or replace jsse.jar with the one included in Update 30 (as I had to because Update 30 was not yet available from Apple).
- Springsource Tool Suite 2.8+ or IntelliJ 10+ (not really required, but allow attached demo project to be run out-of-the-box).
- Disclaimer: Note that the demo project is provided as is without any warranty or obligation and (to give you a head start) as well includes a copy of the Microsoft JDBC Type 4 Driver Version 3 which is to be used with this demo project only and whose use is restricted as explained in MICROSOFT SQL SERVER JDBC DRIVER REDISTRIBUTION LICENSE.
How to change unique constraints to unique indexes?
Alter database DDL within BootStrap.groovy
- Having looked into Hibernate 3.3.1 code (as used by Grails 1.3.7) it appears hard if not impossible to change the DDL generated by Hibernate’s hbm2ddl routines. Thus I resorted to altering table definitions within the BootStrap.groovy code. Please note that the code has been hacked away in a hurry and might fail with advanced usage patterns such as tables belonging to different owners a.s.o. For us it worked out-of-the-box, but use at your own risk.
- The code within BootStrap.groovy is straight forward. It queries constraint data from MS SQL Server information schema and replaces unique constraints that encompass nullable columns with unique filtered indexes.
Supply Hibernate dialect for MS SQL Server 2008
- When a unique index violation occurs, an Exception different from the one when violating a unique constraint will be thrown. MinimalSQLServer2008Dialect contains code to map unique index violations to DataIntegrityViolationExceptions just as if a constraint violation had occurred.
- The demo project has been implemented using Microsoft JDBC Type 4 Driver for SQL Server. This driver returns JDBC type codes (e.g. NVARCHAR for certain information schema columns) Hibernate 3.3 fails to understand. Thus the MinimalSQLServer2008Dialect supplied with this demo project as well provides minimal type declarations in order to successfully query SQL Server information schemas. Another post within this blog will focus on both how to store Unicode strings and how to take advantage of MS SQL Server BIT and xxx(MAX) columns using an enhanced Hibernate dialect.
- The code referenced from DataSource.groovy is contained within class demo.MinimalSQLServer2008Dialect which derives from org.hibernate.dialect.SQLServerDialect. It defines NCHAR and NVARCHAR data types and translates unique index violations to (Spring) ConstraintViolationExceptions.
How to run the code?
Yes, I shout it out to all my fellow brothers – after having led a sinful life of Windows miseries, I now have become a true and humble Apple believer🙂
I wanted to install a web server on my Snow Leopard MacBook Pro in order to hand out some documents and thus ventured into googling for mac install apache. I was quite dissatisfied most articles appeared to be rather involved, requiring to either install by source or mandating other system wide packages to be fetched.
It was no sooner than half an hour I discovered that all that was required is just a single tick within a System Preferences Panel:
- Open Sharing from System Preferences
- Tick Web Sharing
Apache is included off-the-shelf and started immediately after Web Sharing has been enabled🙂
MacMost has a video that includes PHP as well:
This will install Tomcat for developer use – i.e. within your user home path, using your login, not as a service:
- Get the tar.gz for Tomcat Core from Apache Tomcat
- Change to your private Library:
- Unpack Tomcat, e.g.
tar xvfz ~/Downloads/apache-tomcat-6.0.32.tar.gz
- Create symbolic link to remain stable even when upgrading:
ln -s apache-tomcat-6.0.32 Tomcat
- Start Tomcat:
- Stop Tomcat:
Configure at your leasure, e.g. look here for enabling Tomcat Manager Login: http://www.mkyong.com/tomcat/tomcat-default-administrator-password/