Continuous Integration (CI) for Gitbook using Gitlab and Gulp

Gitbook is a static site generator, that converts a collection of Markdown files into a HTML Site. Alternatively it can also convert the markdown files into a PDF or ebook.
If you are not writing a book, it is also a great tool to create a quick documentation for a project you are working on.

Initial set up

We will need gitbook. Gitbook does not automatically generate a SUMMARY.md file, however there is an existing gitbook-summary tool to take care of that.

Gulp will be our taskrunner.

I will deploy to my server via FTP. Since you are only serving HTML Files, there is usually no need for server restart etc.
To integreate it into Gulp I will be using vinyl-ftp.

Gulp

Create a file called gulpfile.js and define your gulp tasks.

You should test especially the “deploy” task locally if everything is working correctly.

Gitlab CI Integration

You need to create a YAML File called .gitlab-ci.yml. Gitlab will recognise the file and run the commands in it.

That’s it. If you push something into the master branch, it will automatically run the commands in the yaml file and deploy your static website to your server.
When the build completes, you will recieve an email, telling you if everything went as planned.

Posted by happyneal in Blog, Web Technologies, 0 comments

CodeWars Kata: File Path Operations

The quick Code Wars Kata I am taking a look at the Kata File-Path-Operations.

My approach to solving the kata was, first to figure out what skills are needed to solve the problem. Since all three problems are similar and try to find a specific pattern in a string, the obvious answer is: Regular Expressions.

The fastest way to learn, create and test your Regular Expressions is using Regex 101.

I solved the Kata using Typescript and this is my final code:

This piece of code would not be suitable for production. It does not take into account of malformed filenames, it would not work for windows;
It would have problems with folders that contain a “.” etc.

If you would be using NodeJS you would use the existing functions in the Path Module.

Posted by happyneal in Blog, Programming, Typescript, 0 comments
Elementary OS: Things to do after installing Elementary OS 0.4 (Loki)

Elementary OS: Things to do after installing Elementary OS 0.4 (Loki)

When you start out with elementary OS there are a couple of useful things that you should do to have  a better experience working with your system.

General

“Software & Updates” for Additional Drivers

The easiest way to install the proprietary NVidia Drivers (in Ubuntu) is to go to System Settings > Additional Drivers and then simply select the driver.

This option is not available in Elementary. However by installing the package software-properties-gtk you can get the program.

sudo apt install -y software-properties-gtk

Now by clicking on Applications on the top right, and then type
“Software & Updates” you can access the Settings.

Easy way to add PPA

With the command line tool add-apt-repository you have a quick way to add additional PPA’s. To get this tool you need to install the package

sudo apt-get install software-properties-common

Add a Minimize Button to Windows

Some of the Elementary Windows do not have an easy way to minimize the window.  With Elementary Tweaks you can add a button to the windows.

Officially the elementary team does not encourage users to use the tweaking tool, since it also exposes switches to functionality that could mess up your system, so use the tool with caution.

sudo add-apt-repository ppa:philip.scott/elementary-tweaks
sudo apt install elementary-tweaks

Microsoft Font Compatability

sudo apt-get install ttf-mscorefonts-installer

Replace Screenshot tool

sudo apt remove screenshot-tool
sudo add-apt-repository ppa:shutter/ppa
sudo apt-get update && sudo apt-get install -y shutter

Chrome

wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
sudo apt-get update
sudo apt-get install google-chrome-stable

Skype

wget https://go.skype.com/skypeforlinux-64-alpha.deb
sudo dpkg -i skypeforlinux-64-alpha.deb

Office

sudo apt install libreoffice

Graphic Editors

sudo apt install gimp inkscape shutter

Video

Video Lan

sudo apt install -y vlc

Codecs

sudo apt-get install ubuntu-restricted-extras ffmpeg

Other

Redshift

A simple program to prevent Eye Strain

sudo apt install redshift gtk-redshift

Laptop Battery Saver

sudo apt install tlp tlp-rdw

Last Steps

Remove Programs

sudo apt remove pantheon-mail -y
sudo apt remove maya-calendar -y
sudo apt remove epiphany-browser -y
sudo apt remove audience -y

Update your system

sudo apt-get update && sudo apt-get dist-upgrade

Posted by happyneal in Blog, Linux, 0 comments
Fix Incorrect Clock Settings in Windows When Dual-Booting With Elementary OS

Fix Incorrect Clock Settings in Windows When Dual-Booting With Elementary OS

Switching between Elementary OS and Windows, I noticed that the Time was not set correctly.  This is mostly caused by Windows and Linux using two different ways of setting time. Linux sets the computers time to the RealTimeClock and then applies the timezone. While Windows simply sets the computers clock to the TimeZone you are currently in.

The classic way of fixing this issue is, changing some value in the Registry. However I use a different – more native to Windows method by using the already existing “Synchronize Time” Task and adding a trigger to ensure that it runs at logon.

Step 1:  Open Task Scheduler

Open the “Task Scheduler” (Press the Windows Key and Type Task Scheduler)

Navigate to the Folder Task Scheduler Library/Microsoft/Windows/Time Synchronisation

Step 2: Set up Trigger

Rightclick on the task “Synchronize Time” > Preferences2016-12-01-00_33_40-nvidia-geforce-overlay

Step 3: Set up a new Trigger

Navigate to the Tab “Triggers” and click on “New”

In the Dialog Box Select Begin the task: “At Log on”

2016-12-01-00_35_47-task-scheduler

 

Now the clock should always be set to the correct time whenever you log on.

 

Posted by happyneal in Linux, Windows, 0 comments
Notes on MITx: 6.005.1x Software Construction in Java (Week 2)

Notes on MITx: 6.005.1x Software Construction in Java (Week 2)

This week the course is covering another two very important topics: Testing and Specifications.

LECTURE 3: Testing

Testing is a very important part of creating functionally correct programs.

Testing will be always incomplete

You will try to test your program using three methods:

  1. Formal Reasoning, essentially you manually verify that your program works correctly
  2. Code Review: Another Programmer takes a look and says everything is ok.
  3. Test Suites: Essentially you write another program (which can have its own bugs) to test your program. You define the inputs and the expected output and compare them.

The course mentions again the residual defect rates of 1-10 defects/kloc(1000 lines of code). Again this does not cite where this number actually comes from. Especially when using Industry Standards and Test Suites this high number would drastically drop to an much lower number. However in the end it only would remain to be an assumption since the actual number cannot be determined.

You testing your program for every possible input (Exhaustive testing) is not feasible. The strategy to simply take a look and see if it works (Haphazard testing) will also not reveal all bugs. The same is true for “Random” testing. All of these test methods cannot be used to test software.

Write Tests

When you are writing tests you should think about how you can make your program fail. Test drive development takes the following approach.

  1. Specify what you want to program
  2. Write tests that would test the specification
  3. Write code so that your code passes the tests

The specification is key to define what inputs are possible and which outputs will be produced. (This also includes throwing errors)

Blackbox testing only focuses on the input and output of the function. These tests do not take into account how the algorithm actually works.

The alternative is Whitebox testing takes into account how the program is implemented.

Test Coverage

Now that you have written tests for all of your code, did you also test all of your code? Coverage takes a look at if all Statements and all possible paths through your code are covered.

There are various Code coverage tools available that you can run and then visually see which part of the code is covered by your tests.

In reality you should try to achieve a coverage of 70-90% of your code achieving 100% is usually not possible due to time constraints. Of course this is not the case if you are using Test Driven Development.

Running Tests

Usually you would create a Testsuite of Unit Tests. You should integrate these tests into your build process to ensure that the tests run automatically. Especially when you modify existing code this will ensure that your modifications will not accidentally break something unintentionally.

When working with multiple people you should add hooks to your git repository that it rejects code that does not pass your test suite.

 

LECTURE 4: Specifications

This lecture is going to cover preconditions and post-conditions in method specifications, and how to write correct specifications.

What is a specification?

The lecture defines a specification primarily only concerning how the interfaces are defined and how the specification document essentially is used as communication device to talk to the client.

Now this actually assumes that the client is another programmer that wants the module/system to do a specific functionality. In my work experience usually the client has no technical background and expects the programmer to know what he wants.  Yes the specification is the key document on how to negotiate which features etc. the client requires, it is however not exactly defined which functions or how interfaces should be created, this is usually the task of the programmer.

The course actually is more talking about a documentation document how and which interfaces exist in the code you are programming for the client. The documentation is key whenever other programmers need to use the code you have programmed.

In either case, the specification document is a key document. It defines the work that needs to be done. The document shields the programmer from the client, if the client forgot to specify something, thus the programmer did not implement it he can prove it was the clients fault. At the same time the programmer is bound to the document that he actually implements all features. (or negotiates, talks with the client that the functionality is unfeasible, or not possible to be implemented)

Pre and Post Conditions

For each function you require the preconditions (what inputs) and postconditions (what outputs).

The inputs may have to have a specific structure, cannot be a certain value etc. These need to be checked.

The function also will have various outputs. This is of course the result, and how the result should be structured, the method also can throw errors.

Write test cases

Essentially if the specification of the function is well defined it is very easy to write the test cases. You simply follow the specification write tests to get the expected correct results and willfully pass wrong arguments into the function.

The rest of the lecture covers how to throw Exceptions. Which to use when.

HOMEWORK

Again another batch of “Java Tutor” exercises. They were as exciting as the last batch…

However this time they also provided a “warm up” problem set. The warm up is just to implement the mathematical “quadratic roots formula”.

The straightforward implementation of the formula will not pass all the Unit Tests. You need to take a deeper look at Java to actually figure out why the last Unit Test fails, and how you can change your code to make your code pass the test.

Posted by happyneal in Blog, Java, 0 comments
Elementary OS: Windows Apps with Play on Linux

Elementary OS: Windows Apps with Play on Linux

One of the major issues when using Linux is that you would like to use Software that was written for Windows. Thankfully more and more new Software is cross-platform compatible. However especially older Software and most newer Games will not support Linux.

If you are dependent on using Windows Software then you have several options available. Dual-Boot Windows and Linux, use a Virtual Machine (like VirtualBox or try  WineHQ

Wine essentially translates the Windows Commands to Linux Commands at run-time. Eliminating the penalty of using a virtual machine. The downside of Wine is, that not all new programs run properly. However it seems games that were written for Windows XP work better with Wine than with Windows 10.

The last time I was playing with Linux I found it very difficult to configure and find packages. You need wine, wine-tricks, then install some other windows package into wine etc.  This time I found another project Play on Linux that provides an easy to use GUI with quick Installers for many different programs.

The other thing which makes “Play on Linux” great, is that it can create multiple virtual drives, for your various programs. So you can use different versions of Wine, or configure the different drives to emulate a different version of Windows, use different components etc.

Install Play on Linux

wget -q "http://deb.playonlinux.com/public.gpg" -O- | sudo apt-key add -
sudo wget http://deb.playonlinux.com/playonlinux_trusty.list -O /etc/apt/sources.list.d/playonlinux.list
sudo apt-get update
sudo apt-get install playonlinux

Battle.net games

Play on Linux shines the most when it already provides an installer that automatically configures Wine correctly to install all components that the program simply runs without any additional work.

You just locate Hearthstone, Diablo or Starcraft from the list and press install and the program will work without any issues.

Windows Steam Games

Step 1

Install Windows Steam. Play on Linux provides easy installers for Steam, simply search for steam in the installer menu and press install.

selection_001

Installer for Steam

 

Step 2

You will have to look up in the Wine AppDB if your game is supported by Wine.

If it is supported you then can log into steam and install games from your library just like in windows.

Step 3

Usually you will need to install some sort of additional windows package to get the program running.

In my case I wanted to install Tron 2.0, in the documentation for the program. Something like needs “winetricks directmusic” was mentioned.

To install “directmusic” you need to select Steam and click on Configure. Then switch to the Install components Tab and then select the component from the list and press install.

selection_003

Install a missing component

 

In some cases, like with my Tron 2.0 example, this is not enough and you have to google some more to find some helpful [article] (http://www.gamersonlinux.com/forum/threads/tron-2-0-guide.628/) that then tells you to install additional components  and not to use the Windows XP emulation but the Windows 7 emulation.

Custom Installers

Of course you may have your own Programs, you can simply click on “Install non-listed program” navigate to the installation files and install your program.

Access to Files

Play on Linux installs a handy shortcut into your home directory, so that you can easily access the various virtual hardrives of the Play on Linux instances, if you have the need to copy&modify files.

 

Conclusion

While Wine is not perfect and not everything runs smoothly and out of the box like when using Windows directy. It is worth fiddling around with Wine/Play on Linux to not have to dual boot or get a VM running.

 

 

 

Posted by happyneal in Blog, Linux, 0 comments