Friday, 6 January 2017

Create and manage Docker images on Windows and Docker Hub

To create a docker image on windows we need to install docker!

https://docs.docker.com/docker-for-windows/

and start the docker service.

Once this has been done prepare a directory structure, where we will organise our Dockerfiles for each image:

O:\sms67pc\docker\images\ 

Create a new directory containing a file named 'Dockerfile' for the image you wish to edit then cd to this directory edit the Docker file and once ready build the image:

# docker build -t [yourtag] 

to run the image interactively (cf login to the image) 

# docker run -i -t [yourtag] /bin/bash 

By logging in your can then test the further commands needed to build the image and add these to the docker file and repeat. Note, the images are not intended to be used as virtual machines and only one command can be run at the end (best to leave further commands to be run in the pipeline scripts; eg bitbucket pipeline will log you in 'interactively') 

You can start the Docker image exposing ports, to example, check the output of HTTP pages by mappng a port eg:

# docker run -i -i [yourtag] -p 8080:80 /bin/bash

If you were to start apache (inside the container) on port 80, then you should be able to view the web pages via http://localhost:8080/

Once happy upload to your docker hub account so that the images can be downloaded by tools like the bitbucket pipelines. 

# docker login 
# docker push [yourtag]

Wednesday, 21 December 2016

Journey splitter

Tuesday, 29 November 2016

Rebase modified branch

you need to put things back first:

git checkout --
git checkout --
git checkout --
git checkout --

then you can:

git rebase origin/master

Friday, 7 October 2016

List the javascript functions available in JQuery or perhaps another library


                var objs = Object.getOwnPropertyNames(jQuery);
                    for(var i in objs ){
                    console.log(objs[i]);
                }

Wednesday, 8 June 2016

Git on linux - a few fixes to some issues

A brief list of issues and ways to resolve when working on linux

Attempting to communicate with the server but this happens eg:

#git remote show origin

(gnome-ssh-askpass:18745): Gtk-WARNING **: cannot open display: localhost:12.0

Yep I do not have a display. Solution;

#unset SSH_ASKPASS

Attempt to push the first version of the repo but this happens:



#git push -u origin master

error: The requested URL returned error: 403 Forbidden while accessing https://github.com/S-Stephen/RECK.git/info/refs


fatal: HTTP request failed

Turns out that I cut and pasted the code from github to setup the repo which included the line:


git remote add origin https://github.com/My-Username/APPNAME.git

This does not include the username I wish to login as I therefor eneed to change this locally to be:

https://My-Username@github.com/My-Username/APPNAME.git

To do this:

# git remote set-url origin https://My-Username@github.com/My-Username/APPNAME.git

And away we go:

I did a #git add * but too much got added including my config/local.js file. 
Before the commit remove this:

# git reset config/local.js

Including emoji / unicode characters to email subject from a scipt

💣 Time to add special characters to your email subjects

I came across this problem when someone asked for emails from my web application to stand out in their inbox.  The emails were informing a user that an alarm had gone off and they would like a bomb or similar to appear in their inbox. 

After a bit of googling and finding many sites that explained how to do this manually (cut and paste characters or using particular 'clipboard' style tools).  I figured out the answer of how to embed the unicode into the message.

So given my script (a nodejs application) I followed the recipe below:

Find the character the user is interested in for example search a site like http://www.fileformat.info

Once you have found the required character locate the UTF-8 (hex string) in the case of the alarm clock (http://www.fileformat.info/info/unicode/char/23f0/index.htm): 'e28fb0'

Embed this in the subject string via: =?UTF-8?Q?=E2=8F=B0?= (ie enclose the hex in =?UTF-8?Q?= and ?=).

Send message and as long as their mail agent supports the character hey hoe!

Monday, 21 September 2015

Sails waterline ORM on an MySQL view



I am required to keep a track of the number of selections a user has made so that when they are below a particular number they can be contacted.

To do this I need to monitor a group by with having count(*) query, for which I decided to generate a view:

create view progress_view as select user.username, display_name, email, year_of_entry, count(*) as num_choices from user left join selection on user.username = selection.username where progress = 1 group by username;

unfortunately defining a regular sails model object fails to load as it complains that we are 'Trying to define a collection (progress_view) which already exists.'

to get around this and to prevent a regular query attempting to retrieve the default fields createdAt, updateAt, id when using the .find() query on the table the following was wadded to the model definition:


var Progress = {
  // Enforce model schema in the case of schemaless databases
  schema: true,

  autoPK: false,
  autoCreatedAt: false,
  autoUpdatedAt: false,
  tableName: 'progress_view',
  migrate: 'safe',

  attributes: {
    username  : { type: 'string', unique: true },
    email     : { type: 'email' }, //,  unique: true },
    display_name     : { type: 'string' }, //,  unique: true },
year_of_entry : { type: 'integer' }, //only on some will be added -> or maybe all, but generally in the inst_name?
num_choices : { type: 'integer' }, //note the minimum here is always 1! evern if the student has not chosen on (as we are identifying with left join)
  }
};

module.exports = ProgressProgress;

hurrah - we can query our view!