Developers and Dark Colour Schemes


Recently at our office our small development team moved from downstairs to upstairs.The upstairs has some skylights so the amount of glare is significantly higher and all of us were complaining about it. What I found fascinating though was the fact that the two of us who use Linux (Centos 7) found the glare situation worse than anyone else.

It didn't take me long to realize the reason for that was that both of us use dark colour schemes which makes the issue of glare worse. So I did a search for Windows 10 screenshots, MacOS screenshots and Linux screenshots on Google Images. Very few of the Windows screenshots show dark backgrounds. With MacOS the number was higher but with Linux the number was significantly higher, particular if any sort of xterm type window was being displayed.

I'm well aware of the fact that most of the screenshots for Windows and MacOS would be for desktops that are not being used for development. What would be interesting to investigate deeper is whether there is any correlation between the amount of time spent in console/xterm type applications and darker colour schemes.

Using Services in Services in Ember


Ember now has the concept of services which are incredible useful and the documentation for how to use them is good. What, however, is not so well covered is how to include a service within a service. In my previous blog post Building an Ember Message Bus I showed how to create an event bus service and inject it into routes, controllers, components and models. However, I soon discovered that the particular work application I was working on I need to be able to access the event bus service from within one of my other services. While this is not difficult there were a couple of gotchas.

When you create a service with ember-cli using the ember generate command then the service name has to be hyphenated, as follows:

ember generate service service-name  

In the particular place were I work we use vx as the first part of the name of our components and then use s as the next letter if it is a service, so for the sake of this blog post we will name the event bus service vxs-eventbus and the service I want to use the event bus service in vxs-consumer.

Now that I had my two service I thought, cool, this should be easy. So in vxs-consumer I had:

import Ember from 'ember';

export default Ember.Service.extend({  
    name: 'vxs-consumer',
    eventbus: Ember.inject.service('vxs-eventbus'),
    etc...

but that didn't work. After doing some more reading and chatting to Alex Speller on the ember IRC channel, I figure it out. Basically, the key to remember is that Ember uses convention over configuration. It makes sense once you see it, but not always before.

To get it to work I needed to do:

import Ember from 'ember';

export default Ember.Service.extend({  
    name: 'vxs-consumer',
    vxsEventbus: Ember.inject.service(),
    etc...

Now Ember looks at this and goes, OK, I need to inject a service, but which one. So it takes the vxsEventbus and by convention changes that to vxs-eventbus, and voila, your service now can use the event bus service. Using it is exactly the same as in the normal case:

this.get('vxsEventbus').publish('_eventName', data);  

where _eventName is the event you want to trigger and the data you want to pass is in data, which is an optional parameter.

Building an Ember Message Bus


When I was looking for an event bus for the Ember application I was writing for work I came across Paul Cowan's blog article called Emberjs - Simple Global Event Bus. This event bus uses the built in Ember.Evented and at it's core looks as follows:

App.EventBus = Ember.Service.extend(Ember.Evented, {  
  publish: function() {
    return this.trigger.apply(this, arguments);
  },
  subscribe: function() {
    return this.on.apply(this, arguments);
  },
  unsubscribe: function() {
    return this.off.apply(this, arguments);
  }
});

I'm using ember-cli 2.4.2 so my actual event bus file and it's associated initializer looked as follows:

import EventBus from '../vxs-eventbus/service';

export function initialize(application) {  
    let eventBus = new EventBus();

    application.register('service:vxs-eventbus', eventBus, {
        instantiate: true,
        singleton: true
    });

    application.inject('route', 'eventbus', 'service:vxs-eventbus');
    application.inject('component', 'eventbus', 'service:vxs-eventbus');
    application.inject('controller', 'eventbus', 'service:vxs-eventbus');
}

export default {  
    name: 'vxs-eventbus',
    after: 'vxs-logger',
    initialize
};

If you are using ember-cli then your service has to have a hyphen in it. Notice that I'm defining it as a singleton and in the export default I'm saying it needs to be initialized after the vxs-logger service.

import Ember from 'ember';

export default Ember.Service.extend(Ember.Evented, {  
    name: 'vxs-eventbus',

    /*
     * Publishes an event to the event bus
     */

    publish: function() {
        return this.trigger.apply(this, arguments);
    },

    /*
     * Subscribe to an event from the event bus
     */

    subscribe: function() {
        return this.on.apply(this, arguments);
    },

    /*
     * Unsubscribe to an event from the event bus
     */

    unsubscribe: function() {
        return this.off.apply(this, arguments);
    }
});

As you can see this is identical to the one in the blog article, just with some documentation.

The interesting part comes when you want to use this. As you can see from the initializer I'm injecting this into routes, controllers and components, so using the event bus in any of those is relatively simple.

this.get('eventbus').publish('_eventName', data);  

where the _eventName is the name you want to use to uniquely identify that event. I tend to use _event as the first part of the name so that I know it is actually an event I'm at looking at but you can use whatever name standard works for you.The data parameter is optional. You can also inject a service into a model as well.

If you want to catch this event in a module then you need to switch it on.

this.get('eventbus').on('_eventName', this, 'functionToCall');  

When the _eventName is called this will cause the functionToCall to be run with the associated data you passed in the event.

One thing you did need to remember to do though is when you leave that route for example is to switch the event off, otherwise next time you go into that route the event will get called twice. So:

this.get('eventbus').off('_eventName', this, 'functionToCall');  

Where exactly you switch the events on and off will depend on how you are using and whether they are page wide or just component wide.

The interesting part comes when you want to use the event bus in another service. We will look at that in the next entry Using Service in Services in Ember.

The Definition of Marriage


There has been a lot of Christian articles recently on the whole "gay marriage" issue and after reading a fair number of them (both for and against) they all seem to have the same issue - they are working with an incorrect definition of marriage and as a result draw erroneous conclusions.

Genesis 1 and 2 are normally taken as the bedrock of where marriage is defined. At this time the world was perfect so there was no need for either party to be protected from anything as sin had not yet entered the world. And so in Genesis 2:24 we read:

For this reason a man will leave his father and mother and be united to his wife, and they will become one flesh (Genesis 2:24 NIV)

And that's what marriage is. There are a lot of things we have added to it but at it's core that's it. The church has implicitly assumed this through the ages, even if not explicitly, as they recognised that an unconsummated marriage could be declared null en void because the marriage had never taken place. It also means you don't have to be a Christian to get married. Any male and female that engage in sex get married. As Christians we implicitly recognise this in not forcing people who were not married in a church to get "(re)married" if they become Christians. We recognise that the church part of it is completely irrelevant.

Does the rest of Scripture support that definition? Paul writes this in 1 Corinthians 6:16:

Do you not know that he who unites himself with a prostitute is one with her in body? For it is said, "The two will become one flesh." (1 Corinthians 6:16 NIV)

So you have married as many people of the opposite sex you have had sex with. This also turns the whole no sex before marriage thing on its head. Jesus makes this even clearer. In Matthew 19:4 he says:

"Haven't you read," he replied, "that at the beginning the Creator 'made them male and female', and said, 'For this reason a man will leave his father and his mother and be united to his wife, and the two will become one flesh'? So they are no longer two, but one. Therefore what God has joined together, let man not separate." (Matthew 19:4-6 NIV)

So if we use the sexual union of male and female as the definition of marriage (which I believe is the only definition of marriage found in the Scriptures) then the whole issue of "gay marriage" becomes a non-issue, not because of anything the church says or anything the state says but because, very simply, it is physically impossible for them to get married.

So what about church "marriage"? If we use the above definition then the church does not marry anyone - in fact it can't. What the church does is provide a platform where the couple can exchange vows before God and witnesses. This has a two fold purpose. One is that the couple are making vows before God that they will stay together for the rest of their lives. This makes divorce among Christian couples far more serious than among non-Christian couples who have not made any vows to God. A secondly it provides witnesses who hear them make the vows and can keep them accountable to those vows. It's interesting that the Puritans didn't believe the church should be involved in "marrying" people - they considered it purely a state issue.

And what about state "marriage"? Again, using the above definition of marriage the state does not marry anyone. What it does however is provide legal protection for two or more parties. Essentially, the state provides a cohabitation contract, which can be between a male and female, two males, two females or any other combination of people. The only requirement is that all the parties be of legal age. France went down this route and I believe this is the correct way for the state to handle this issue. Whether or not the two or more parties are having sex or not is completely irrelevant in terms of the contract. And it is right that the state does this as it is the state's role to protect it's citizens, both from external harm as well as internal harm. So technically the state legislation should have no reference to the term "marriage" in it at all. It's irrelevant and confuses the issue.

So should gays be able to be "married"? If you mean by that should they be able to enter into the same legal contracts that "married couples" do then yes. If you mean should they be able to get "married" in a church then no. But then even a man and woman can't get "married" in a church either.

There is a lot more I could write about this topic (e.g. adoption of children and "marriage") but that's probably enough for now. Maybe I'll pick up the pen another day and write some more.

Ghost Local Mail Setup


All of my servers use a local copy of exim to forward mail to my mail server so that any messages generated out of cron etc. are forwarded to me for checking. By default the blogging platform Ghost assumes you are going to send the emails it generates directly to an external mail host like Gmail.

Looking around the web I came across this posting:
https://ghost.org/forum/installation/529-use-local-smtp-server-for-sending-email/

With a bit of experimentation though I discovered I didn't need to do all the other steps mentioned in this posting. All I did was change my config.js to have:

mail: {
    transport: 'SMTP',
    host: '127.0.0.1',
    options: {
        service: 'SMTP',
        requiresAuth: false,
    },
},

and it worked.