Udacity – Web Tooling and Automatisation

I recently took a look at the course materials for Web Tooling and Automatisation.

Overall the course is very well structured and introduces Gulp and a couple of common packages used in webdevelopment. Besides their main topic, they cover topics on good engineering practices, like linting and testing to ensure code quality.

While working on the project I ran into several little smaller things that were quite annoying. Thankfully the gulp community is quite big, so somebody already solved some of the issues I was facing.

Passing an “--production” flag

When developing, you will probably create a version of your software that is suited for easily finding bugs and errors and an optimized version that is minified and optimized for optimal performance for the end user.

You would define two different tasks in gulp, one “default” and one “production” task. This however would in turn cause you to have to duplicate your code – with optimization and without.

I found the package “gulp-if” that allows you to control if a function like compression is active during the task.
The remaining issue was to actually set the parameter before the tasks run. (All tasks in gulp run in parallel).

To get a flag from the command line, you can use the process.argv Array. However you must add “–” before your flag name. If not gulp will assume it is another task name that should run.

In the end you would use something like this:

Note: In Gulp 4, you can use a sequencer and would not need to pass in the flag by command-line, but you would define a task that will run before all the other tasks.

Dealing with Asset sources and destinations

When using gulp.src() and gulp.dest(), typically people use strings to define the locations. However this is quite annoying if you want to get a quick overview which locations are used. For a better maintainability you should create a small variable block that defines these strings. In the long run it lets you be more flexible where your files are etc.

End Result

At the end of the course I ended up with this gulpfile.js. It adds support for Typescript, Pug(Jade), google-closure-compiler.

The common gulp tasks to run are:
* gulp serve: Uses browser-sync with css injection for live-editing
* gulp --production: Creates an optimized build

Next steps:
Depending on your webserver, you would want to add a gulp deploy task.



Posted by happyneal in Web Technologies, 0 comments

NPM: Use Github Patch Instead of Repository

Recently I was playing around with the HEXO static site generator.
For my setup I was using Hexo in combination with Gitlab CI and the ftp deploy method.

The module hexo-deployer-ftpsync has an issue that you need to manually confirm that the ftp deployment succeded.
In essence it does not exit on its own, thus a CI environment would not be able to automatically verify the success or failure of the build, it would just run forever.

Github allows you to fork existing code, improve upon it and issue a pull request, that your code will be integrated into the main software build.
I changed a couple of lines to ensure that the ftp deploy process would terminate.

To use my patch instead of the current master build of the module you need to adjust the package.json file.
Simply replace the version-number with the github url <username/project>#

Original: With Version Number

New: With github path to patch

If the owner of the project integrates my suggestion on how to fix the bug, then the line can be changed back to the offical master branch of the code.
However for the time being, gitlab CI uses the alternative code and successfully deploys my code to the server.

Posted by happyneal in Programming, 0 comments

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.


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.


“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 &amp;&amp; sudo apt-get install -y shutter


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


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


sudo apt install libreoffice

Graphic Editors

sudo apt install gimp inkscape shutter


Video Lan

sudo apt install -y vlc


sudo apt-get install ubuntu-restricted-extras ffmpeg



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 &amp;&amp; sudo apt-get dist-upgrade

Posted by happyneal in Blog, Linux, 1 comment
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”



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


Posted by happyneal in Linux, Windows, 0 comments