Converting Less to Sass

We converted our project from Less to SCSS. Our original decision to go with Less rather than Sass hinged around Bootstrap 3’s use, along with the fact that the original Sass syntax was a turn-off.

With SCSS being the way forward, the original objection to the boutique Sass syntax was eliminated. With Bootstrap 4 on the horizon and its adoption of SCSS, we decided to look into the effort to convert.

Because Less and Sass essentially do the same thing, this fortunately was quite straightforward. We had to be careful to ensure the variables got the $ and @mixin and @import were properly put into place.

The only problems were uncaught CSS goofs. More time was spent reconfiguring the Gruntfile to work with grunt-sass.

 

AngularJS 1.6 Bindings Inconsistent? No, just RTFM.

When upgrading our major project from AngularJS 1.5 to 1.6, I read through the release notes when I was fatigued and the impact of the changes to $compile didn’t sink in.

As changes are made to this large project, code is being adapted towards better Angular (2+) compatibility. I added a new controller in TypeScript and used the controller as approach of binding to the controller object rather than $scope. Without thinking what I was doing, I set a default value for a bound class variable in the class definition:

class MyController {
    public somethingAwesome: string = DefaultStringValue

In the template HTML:

<input ng-model="$ctrl.somethingAwesome">

And “somethingAwesome” became undefined no matter how  much anybody pounded on the keyboard.

The release notes for $compile state, “Due to bcd0d4, pre-assigning bindings on controller instances is disabled by default”, and reminds us, “Initialization logic that relies on bindings being present should be put in the controller’s $onInit<() method, which is guaranteed to always be called after the bindings have been assigned."

Having been chastised by the documentation for my lapse, I sheepishly added an $onInit() method to the class and quietly checked it in.

 

Bash on Windows 10

I was pleasantly surprised to see that there is beta support for a Ubuntu-based bash on Windows 10.

An introduction is here, along with an Installation Guide on the MSDN website.

apt-get pulls an obsolete version of NodeJS. To load the latest (as of today) NodeJS, use the following commands with root privileges:

apt-get -y update
apt-get install git
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
apt-get install -y nodejs

Install NodeJS and MongoDB on CentOS 7

As always, I’m sharing my personal notes here. I’ve used virtual machines for development since the first version of VMware. I’ve been using DigitalOcean’s services for some time. I generally use their CentOS 7 install.

NodeJS

Update: I have newer install instructions here.

Edit: Removed old instructions.

Some native add-ons from npm require build tools. If you anticipate needing those, install:

yum -y install gcc-c++ make

MongoDB

Installing MongoDB’s community edition requires creating a yum repo file, a a system configuration file, and then a reboot.

vim /etc/yum.repos.d/mongodb-org-3.2.repo

and fill it with the following text:

[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc

which allows MongoDB to be installed with a simple:

yum install -y mongodb-org
service mongod start
chkconfig mongod on

Getting Rid of Warnings

If you use the mongo client, you’ll notice the following warnings:

Server has startup warnings:
2016-09-04T18:27:20.393+0000 I CONTROL  [initandlisten]
2016-09-04T18:27:20.393+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-09-04T18:27:20.393+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-09-04T18:27:20.393+0000 I CONTROL  [initandlisten]
2016-09-04T18:27:20.393+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-09-04T18:27:20.393+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-09-04T18:27:20.393+0000 I CONTROL  [initandlisten]
2016-09-04T18:27:20.393+0000 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 4096 processes, 64000 files. Number of processes should be at least 32000 : 0.5 times number of files.
2016-09-04T18:27:20.393+0000 I CONTROL  [initandlisten]

The soft rlimits warning can be fixed by creating a file:

 vim /etc/security/limits.d/90-nproc.conf

and putting the following line in it:

mongod     soft    nproc     64000

and rebooting the system.

The transparent_hugepage warnings can be fixed by creating a file:

vim /etc/init.d/disable-transparent-hugepages

and filling it with:

#!/bin/bash
### BEGIN INIT INFO
# Provides:          disable-transparent-hugepages
# Required-Start:    $local_fs
# Required-Stop:
# X-Start-Before:    mongod mongodb-mms-automation-agent
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Disable Linux transparent huge pages
# Description:       Disable Linux transparent huge pages, to improve
#                    database performance.
### END INIT INFO

case $1 in
  start)
    if [ -d /sys/kernel/mm/transparent_hugepage ]; then
      thp_path=/sys/kernel/mm/transparent_hugepage
    elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then
      thp_path=/sys/kernel/mm/redhat_transparent_hugepage
    else
      return 0
    fi

    echo 'never' > ${thp_path}/enabled
    echo 'never' > ${thp_path}/defrag

    re='^[0-1]+$'
    if [[ $(cat ${thp_path}/khugepaged/defrag) =~ $re ]]
    then
      # RHEL 7
      echo 0  > ${thp_path}/khugepaged/defrag
    else
      # RHEL 6
      echo 'no' > ${thp_path}/khugepaged/defrag
    fi

    unset re
    unset thp_path
    ;;
esac

ensuring it runs at startup:

chmod 755 /etc/init.d/disable-transparent-hugepages
chkconfig --add disable-transparent-hugepages

and then, finally, rebooting. The mongo client should start without warnings now:

 
MongoDB shell version: 3.2.9
connecting to: test
>

 

 

Notes on Signing Keys for PhoneGap Build

As always, this site contains notes to myself which others may (or may not) find useful. They may contain errors. Corrections and clarification is gratefully accepted. I apologize that these notes are somewhat abbreviated.

Android

The instructions on the Adobe PhoneGap Build web site don’t properly display on all platforms. The core information is as follows.

Google uses the Java keytool program, which creates a database of cryptographic keys & certificates. If you have Java installed, keytool should be available. The example command is as follows:

[code lang=”bash”]
$ keytool -genkey -v -keystore [keystorename].keystore -alias [aliasname] -keyalg RSA -keysize 2048 -validity 10000
[/code]

iOS

iOS is more complicated. This requires access to an Apple machine running OS X.

The first step  is to ensure that your Keychain Access program has the latest root certificate. As of this writing (16 June 2016) it is AddTrust External CA Root with an expiration date of 30 May 2020 at 4:48:38 a.m. (I solved this with a web search.)

Create a Distribution Certificate

Next, log into your developer.apple.com account. From the top menu, go to your Account. On the left-hand vertical bar, select Certificates, IDs & Profiles. Create an iOS certificate with the type iOS Distribution.

Create a .p12 File

Download the certificate and load it into Keychain Access. (The certificate should have a submenu showing your private key. If it is not there, you can’t export it as a .p12 file.) Right click on the certificate and export it as a .p12 file.

Load Devices for “Ad Hoc” Testing

To bypass the Apple gatekeepers for testing, you need to specify the unique device IDs (UDID) for every iOS device that the app is allowed to run on. Those are listed under Devices on the left-hand side.

Create a Provisioning File

If you want to bypass the Apple gatekeepers for testing, you need to create a new iOS provisioning file with the type Ad Hoc under the Distribution heading. This will allow to choose the certificate, application ID, and the UDIDs to enable for testing.

If you’re to the point where you want to submit your app through the Apple store, create a provisioning file with the type App Store under the Distribution heading. You will not be given the choice of selecting specific UDIDs this turn.

Loading Keys in the PhoneGap Build Site

Lastly, log into the Adobe PhoneGap Build site and go to Edit Account. The second tab is Signing Keys. Under the appropriate OS, hit the add a key … button and upload your keystore (in the case of Android) or .p12 and provisioning files (in the case of iOS).

These keys should be ready to use for building your app.