Archive for February, 2017

February 23rd, 2017
1:03 pm
Angular2 Tour of Heroes Tutorial – Issues and Learning Points

Posted under Angular
Tags ,

Whilst adding the changes to for 2 way data binding by adding the new file src/app/app.module.ts as detailed here, VS Code reported the following errors:-

[ts] Cannot find module ‘@angular/core’. (1,24)
[ts] Cannot find module ‘@angular/platform-browser’. (2,31)
[ts] Cannot find module ‘@angular/forms’. (3,31)

The compilation was not affected and the app worked.

The notes state that you should add it to the NgModuledecorator’s imports array, however this decorator and indeed the above file were not even present in the project.

Having looked into it, it appears that the available git repos do not match the tutorial notes! Annoying! There might be a VS Code issue but it looks likely that it is a repo issue.

The standard repo is here. This appears to already have the changes listed above for  app.module.ts, so is not suitable for starting the tutorial.

The version I used from Rob Lourens, which contains the launch.json configurations for VS Code, is here. This is different again, and still does not match the tutorial start!

No Comments »

February 22nd, 2017
10:28 pm
Angular2 Tour of Heroes Tutorial – IDE/Debugging Setup

Posted under Angular
Tags , ,

The aim of this was to get the tutorial up and running in a suitable IDE, such that I could debug and step through the code whilst understanding it. The tutorial site is here. The standard repository on Git is here.

A number of different IDE options where tried, and most of them hit problems and were therefore discounted. The options tried were as follows:-

Eclipse with the Angular 2 Eclipse plugin

The following links document how to set this up:-

http://fcorti.com/2016/08/22/angular-2-eclipse-how-to/

http://stackoverflow.com/questions/35890887/how-to-get-angular2-to-work-in-eclipse-with-typescript

When loading the Tour of Heroes tutorial, I tried to import it as a file system project as the cloned Git repo was not an ecplipse project.

The problems I hit with this were as follows:-

  1. After importing into eclipse, there were compile errors on import and export statements in rollup.js.
  2. The core problem appeared to be eclipse bug 496348 which was listed as resolved but judging by the comments at the end was still a problem.
  3. I tried various ways around this, such as upgrading to a dev release of eclipse Neon, trying a prerelease of eclipse Oxygen, and upgrading the eclipse plugins. None of these solved the problem.
  4. As this was not a very commonly used IDE, there was not that much in the way of online help. In particular, no-one appeared to have posted online about getting the Tour of Heroes demo working with it. Therefore, support etc. going forward would likely be a problem.

Webclipse

  1. This is a paid for eclipse plugin, also available as a separate IDE on its own called Angular IDE, detailed   here.
  2. I tried this also with Eclipse Neon and Oxygen, and received similar Typscript related errors that I could not eliminate when trying to load the Tour of Heroes demo. I therefore dumped this too.
  3. Whilst I did not try IntelliJ/Webstorm at this stage, which was the Jetbrains/IntelliJ paid for option, one Stack Overflow comment (which I now cannot find) cited that there were still Typescript issues with it, even in IntelliJ. (With hindsight, I wish I had, as in the end I have standardising on it as it works both for this tutorial, which uses systemjs, and for applications generated via angular-cli which use webpack. Details on this stage of the journey here and here).

Visual Studio Code

  1. This is the IDE I settled on at this stage. Whilst it meant learning another IDE, it had a number of overriding benefits.
  2. Basically it just works with no problems and no wacky Typescript errors! The basic point here is that Microsoft originated Typescript, and they are the authors of VS Code, so unsurprisingly it has the best compatibility.
  3. As it is probably the most commonly used IDE for Angular, unlike with the other IDE solutions, there are many examples online for it, including for the Tour of Heroes tutorial, which needs a custom launch.js file for running the demo.

 

The setup steps for it were as follows :-

  1. Follow the initial steps including installation of the latest Node.js and npm from the Angular tutorial site here
  2. Rob Lourens has forked the Tour of Heroes git repo here, with a custom launch.js file for launching in VS code. Clone that git repo and follow his instructions.
  3. Note that this uses the VS Code debugger for Chrome extension, in order to allow browser run angular JS code to be debugged inside VS Code instead of in the Browser.
  4. In order to get this working, I had to start the app from the command line first via npm i (to build) then npm start.
  5. Also, initially I could not get VS code to connect to Chrome, either by running up a new chrome via Rob’s launch.js configuration “Launch localhost with sourcemaps”, or by connecting to an existing chrome using “Attach with sourcemaps”. The issue was that Chrome needed starting with a command line option to allow debug connections via its debug port. This is detailed here (comment by auchenberg) – the command line is C:\Program Files (x86)\Google\Chrome\Application\chrome.exe –remote-debugging-port=9222
  6. Once the above was done, I could connect from VS code provided I tried to attach to the existing chrome using  “Attach with sourcemaps” – otherwise, a new chrome was started which did not allow debug connections!
  7. The steps needed were therefore 1/ run (having built) using npm-start, 2/ run up a debug chrome, then 3/ click on the debug icon in VS code, select the  “Attach with sourcemaps” dropdown launch.js option, then hit the green go button just to the left of it. This successfully fired up the demo.
  8. Note that I was able to breakpoint in the code using VS code either on the Typscript (.ts) files or the equivalent transpiled .js files. It appears that the compiled code is interspersed in the same folders as the Typescript, which does not seem cool at all – something to look into. I would expect that the build artifact code would be separate as in Java.

No Comments »

February 16th, 2017
10:45 pm
Angular 2 Tutorial/Information Links

Posted under Angular
Tags

Getting Started with Angular 2 using TypeScript

Quickstart – ts – QUICKSTART

Learning Angular – ts – GUIDE

Architecture Overview – ts – GUIDE

Angular Example – Intro to Angular – Plunker

This link contains some real world experience from a phonegap/cordova developer, so useful input. Note that it may not all apply to ionic so check the comments as there was one about ionic.

https://agingcoder.com/programming/2015/02/21/lessons-learned-from-5-years-of-phonegapcordova-development/

No Comments »

February 15th, 2017
10:18 pm
CouchDB Range Searching–collation sequence tricks with arrayed keys

Posted under CouchDB

Here is an example of a range query. The keys are arrayed, of the form

[postTown, locality, name, id, 0] for the place document, and:-

[postTown, locality, name, id, 1] for the immediately following placeFeatures document.

(Assuming ?include_docs=true is used to include the documents)

http://localhost:5984/places-guide/_design/places/_view/placesByLocationName?include_docs=true&start_key=["Norwich","Neatishead"]&end_key=["Norwich","Ranworth",{}]

 

Here is one with the same start and end keys:-

http://localhost:5984/places-guide/_design/places/_view/placesByLocationName?include_docs=true&start_key=["Norwich","Neatishead"]&end_key=["Norwich","Neatishead",{}]

Note that in this case, we have had to append the null object as the next element in the key, or the query would return nothing at all. This works because the null object comes last in the collation sequence, i.e. after all possible values for the name element of the key, so this allows all places for Neatishead to be included.

The opposite of this is “”, the empty string (or a null), both of which come first in the collation sequence.

The trick is documented in this Stack Overflow post here

No Comments »

February 15th, 2017
10:07 pm
CouchDB Useful Links

Posted under CouchDB

This stackoverflow post is a good comparison re using PouchDB + CouchDB vs using CouchBase Lite (which also runs on Android). For what I’m doing Pouch/Couch still looks right as it allows seamless switching between the pouch and couch, and has an http api usable for both, plus all the replication

http://stackoverflow.com/questions/18416289/differences-between-pouchdb-and-couchbase-lite-litegap

However, if I ever did decide to switch, the concepts/views/Map-Reduce stuff all look pretty much the same, so it looks like a switch wouldn’t be too painful.

http://docs.couchdb.org/en/2.0.0/couchapp/views/index.html

This is really good on how rereduce works!!!

Also talks about the basics of group_level, under grouping

https://wiki.apache.org/couchdb/Introduction_to_CouchDB_views

http://docs.couchdb.org/en/2.0.0/couchapp/views/intro.html

http://docs.couchdb.org/en/2.0.0/couchapp/views/collation.html

http://docs.couchdb.org/en/2.0.0/couchapp/views/joins.html

http://docs.couchdb.org/en/2.0.0/couchapp/views/nosql.html

https://wiki.apache.org/couchdb/Built-In_Reduce_Functions

Normalisation guidelines etc.

http://stackoverflow.com/questions/1530745/principles-for-modeling-couchdb-documents

Modelling Entity relationships

https://wiki.apache.org/couchdb/EntityRelationship

http://stackoverflow.com/questions/16188519/optimal-way-to-model-documents-hierarchy-in-couchdb

http://stackoverflow.com/questions/1530745/principles-for-modeling-couchdb-documents?rq=1

http://stackoverflow.com/questions/6129561/retrieving-hierarchical-nested-data-from-couchdb

https://www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=couchdb%20nested%20documents

http://www.ibm.com/developerworks/opensource/library/os-couchdb/index.html

http://stackoverflow.com/questions/1680408/couchdb-a-real-world-example

Dynamic Views

https://www.google.co.uk/search?q=couchdb+dynamic+views&ie=utf-8&oe=utf-8&client=firefox-b&gfe_rd=cr&ei=829FWPuXBa3S8AePqYuQCw

http://stackoverflow.com/questions/5583318/couchdb-accessing-querystring-parameters-in-views

http://stackoverflow.com/questions/5596844/couchdb-emulating-dynamic-parameters-with-views

Update Handler Example

https://www.google.co.uk/search?q=couchdb+change+a+view+programmatically&ie=utf-8&oe=utf-8&client=firefox-b&gfe_rd=cr&ei=Y3BFWIWiNq3S8AePqYuQCw#q=couchdb+update+handler+example

CouchDB Best Pracitices

https://ehealthafrica.github.io/couchdb-best-practices/

No Comments »

February 4th, 2017
4:24 pm
MantisBT Upgading

Posted under Hosting
Tags , ,

Update 18/10/2019 – file permission issue after unzip of new version

I upgraded to 2.22.1.  When the install zip was unzipped on the server, all the files and directories had group write access. This was not the case for previous installs/upgrades, and I was not clear on the cause.
This causes the upgrade script to fail, as the version of PHP in use disallowed the scripts from running with this permission present.

To remedy this I tried changing the permissions a directory at a time in the CPanel file manager but this was very time consuming.

I then tried to connect via SSH to the CPanel hosting, but this failed and timed out. It should be possible to enable it in Cpanel as per here but the Zen CPanel does not have this and does not seem to allow it.
The Zen support boards did not have anything on this either.

In the end I found that FileZilla can do it as per this post here.
It can recurse subdirectories, and also crucially all the check boxes are tri-state so they can either be “force on“, “force off“, or “leave as was“, so I could use the same recurse to fix both directories and all files to remove group write but leave everything else alone, given that other directory permissions are different to those of files and I didn’t want to mess with them.

This worked fine, and allowed the Mantis install script (which also does upgrades) to run.

When upgrading, the script helpfully does a precheck of requirements for the upgrqade. It said that a db type in the config script of ‘mysql’ was legacy and not supported in the zen configuration, so it said to change this to ‘mysqli’ in the config_inc.php file.
This then passed all the prechecks and the upgrade ran quickly and cleanly.

Original Version

This is fairly straight forward (apart from the database permissions issue below) and is documented here.

For additional information about initial installation of MantisBT see here.

The steps I performed were as follows:-

  1. Backup the site including the MySQL databases
  2. Rename the existing Mantis installation on the site to another folder for easy backout.
  3. Upload the installation zip to the site, and unzip.
  4. Rename the unzipped directory to the desired target name (in my case, mantis)
  5. Copied the config_inc.php from the old installation to the new one. Note that in my case the config had been moved in the new version to a config subfolder under the installation directory.
  6. Compared the copied config_inc.php with the sample one in config_inc.php.sample, to reconcile any config changes in the new version. In my case, going from version 1.2.4 to version 2.1.0, I had to add an entry for $g_crypto_master_salt which was not present in the old version. To create the salt I used the WordPress salt creation site here as Mantis did not have a convenient one, and it was not straightforward to create a random salt under windows.
  7. Run the database upgrade script (see note below about permission issues).
  8. I also used the Directory Privacy option under cPanel to force a username and password to allow access to Mantis (in addition to the login that Mantis provides). Note that when renaming the existing Mantis installation in step 2/ the existing directory privacy settings moved with the renamed directory.

Database fails to upgrade database due to permission errors

This was found when upgrading from 1.2.4 to the latest version at the time, 2.1.0.Running the upgrade database script gave errors on alter table commands, even though the user for that particular hosted database had full permissions. The solution was to use the overall master account for database access, which allowed the script to run. This is described in more detail here.

No Comments »

February 4th, 2017
4:21 pm
Zen MySQL Hosting and Permission Issues

Posted under Hosting
Tags , ,

cPanel MySQL access is provided by the phpMyAdmin application.

When creating MySQL databases for different applications, each get their own database schema and user, but their is also a master user which has the same username and password as the cPanel hosting (in my case, swoodley/…..).

This is relevant as I have found during upgrading some hosted software where a database upgrade script needs to be run, sometimes the script fails when run under the username for the specific schema with permission errors e.g. on alter table, even though the user has full permissions. This occurred in particular when upgrading Mantis BT. This appears to be because the script in question contains specific database schema references when referring to tables, of the form mydb.tablename. This kind of reference fails when run using the login account for the particular database schema.

Logging in using the master user solved the problem. It may be that modifying the script to take out specific schema references may then allow it to work with the schema/database account rather than the master one. However, this was not necessary in my case.

No Comments »