Make Gadgets Work

Install R using following commands: sudo apt-get install r-base libapparmor1 gdebi-core # Check that R is installed R #quit R q() Install Rstudio IDE server cd Downloads/ wget https://download2.rstudio.org/rstudio-server-1.0.136-amd64.deb sudo gdebi rstudio-server-1.0.136-amd64.deb At this point if all goes well you can check the status of rstudio server by issuing the command: sudo systemctl status rstudio-server.service The server is started automatically at port 8787 and can be accessed using in browser of your choice, provided all firewall settings have been taken care of. However, when you open the Rstudio server you will be presented with a logon screen and while you can access this using the users for the machine it is hosted on, it will be prudent to create a lower privilege user as explained in next section. Add User to access the RStudio sudo adduser rstudio Set up SSL and reverse proxy for R-Studio Server Now important thing to note is that community version of Rstudio server does not come with SSL enabled but just to run it on a secure socket layer you don't necessarily need the pro version. By following the steps below, your communication with the server will be on SSL. However to achieve the objective we need to accomplish following steps: Enable modules on Apache to help set up proxy Configure a proxy to control access to RStudio Server Use LetsEncrypt to enable SSL Restrict access to Rstudio server only through proxy Restart both Rstudio and Apache servers Step 1: Enable modules on Apache to help set up proxy There is guidance on how to do this on Rstudio Support. However, there was a bit of hair pulling and head scratching involved to get all the steps above work together so stick with me but keep that link in back pocket for variations or when you are stuck. With head scratching and hair pulling I mean that I encountered errors such as these - AH01102 error reading status line from remote server, Rstudio Proxy redirect changing the URL to localhost and many others which can be avoided by following steps as explained below. Anyway so we need to enable mod_proxy and mod_proxy_wstunnel modules. As Apache is already installed and mod_proxy already enabled I did not have to install the module itself, but if it needs to be done the commands are: sudo apt-get install libapache2-mod-proxy-html sudo apt-get install libxml2-dev Issuing the following commands should enable the relevant modules: sudo a2enmod proxy sudo a2enmod proxy_http sudo a2enmod proxy_wstunnel Step 2: Configure a proxy to control access to RStudio Server # Change directory to sites-available cd /etc/apache2/sites-available # create a rstudio conf file sudo nano rstudio.conf Paste the following in the conf file but make sure to change details relevant to your set-up for each entry (line numbers 2, 3, 4, 15 and 16 below): <VirtualHost *:80> ServerAdmin user@yoursite.com ServerName yoursite.com ServerAlias whatever.yoursite.com #Specify path for Logs ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined RewriteEngine on #Rewrite the url supplied to ensure https is applied RewriteCond %{SERVER_NAME} =yoursite.com [OR] RewriteCond %{SERVER_NAME} =whatever.yoursite.com RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent] # Following lines should open rstudio directly from the url RewriteCond %{HTTP:Upgrade} =websocket RewriteRule /(.*) ws://localhost:8787/$1 [P,L] RewriteCond %{HTTP:Upgrade} !=websocket RewriteRule /(.*) http://localhost:8787/$1 [P,L] ProxyPass / http://localhost:8787/ ProxyPassReverse / http://localhost:8787/ </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet Press Ctrl+x and save the file. TIP: If you just want reverse proxy and no SSL, you can just comment out line 15, 16 and 17 in above conf file and you are all set. If you do want to enable SSL, enabling the site with commands below won't probably work just yet and subsequent steps will need to be completed. Now enable the new site by issuing the commands: sudo a2ensite rstudio.conf sudo service apache2 restart Step 3: Use LetsEncrypt to enable SSL Follow the instructions here for specific usecase but one way or the other using Certbot you will be able to obtain the LetsEncrypt SSL certificate and enable it on your server. Once certbot has completed doing it's thing you would find an additional conf file in /etc/apache2/sites-available named rstudio-le-ssl.conf. It will be pretty much same content as in rstudio.conf with very minor changes. The first line will be listening on 443 instead of 80 and the ssl certificates will be included. Normally you would not need to tweak anything in the resultant file but just for reference the contenst of this file will look as below: <IfModule mod_ssl.c> <VirtualHost *:443> ServerAdmin user@yoursite.com ServerName yoursite.com ServerAlias whatever.yoursite.com ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined RewriteEngine on # Following lines should open rstudio directly from the url RewriteCond %{HTTP:Upgrade} =websocket RewriteRule /(.*) ws://localhost:8787/$1 [P,L] RewriteCond %{HTTP:Upgrade} !=websocket RewriteRule /(.*) http://localhost:8787/$1 [P,L] ProxyPass / http://localhost:8787/ ProxyPassReverse / http://localhost:8787/ SSLCertificateFile /etc/letsencrypt/live/whatever.yoursite.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/whatever.yoursite.com/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet </IfModule> Restrict access to Rstudio server only through proxy Finally, we want to ensure that access to the Rstudio server is only through the proxy we configured and to do that we just need to specify this in the rstudio server configuration the attribute that tells it to only serve requests from localhost. sudo nano /etc/rstudio/rserver.conf Now on the opened file type www-address=127.0.0.1 and press Ctrl+x and save the file. Restart both Rstudio and Apache servers Finally issue the following commands to restart both the servers: sudo systemctl restart rstudio-server.service sudo service apache2 restart This is it. Now your new Rstudio server is ready to be used through secure socket layer.

Rstudio Server Setup with SSL behind Apache proxy server

Install R using following commands: sudo apt-get install r-base libapparmor1 gdebi-core # Check that R is installed R #quit R q() Install Rstudio IDE server cd Downloads/ wget https://download2.rstudio.org/rstudio-server-1.0.136-amd64.deb sudo gdebi rstudio-server-1.0.136-amd64.deb At this point if all goes well you can
For a fairly long time, I have been looking for a simple markdown type of solution to be able to quickly draw Gantt charts but never came across what one would call a quick option. It has always been an involved process. To my simplistic mind, a simple solution would just be an option where I can type the action, a start date and an end date for the action line after line and it get's displayed in the Gantt chart. The latest edition of Linux Format (Issue 221, Page 52) had mermaid as one of the hotpicks and highlighted the availability of Gantt charts which piqued my interest, I tried the solution and it is indeed what I was looking for. There are a few rough edges but it is a working solution and in normal circumstances will save considerable time and hence will become my tool of choice. There are few ways of using it and because it has been made to work with MarkDown syntax, it can work on a number of tools too. I found CuteMarkEd to be the easiest one to use but the various ways to use it are listed below and their usage explained in following sections: CuteMarkEd Install Mermaid CLI Install Markdown Plus Mermaid Live Editor Install CuteMarkEd CuteMarkEd is not available in debian repositories nor does it have a binary for debian. Although it does have an rpm binary. As I have been playing with Debian / Ubuntu based Elementary OS lately, instead of my regular Fedora install, I figured might as well compile from source code. Steps are as below and are also available on the github page for CuteMarkEd: #Prepare the environment for building from source code. sudo apt-get install build-essential checkinstall git #Get the code from github git clone --recursive https://github.com/cloose/CuteMarkEd.git #Install dependencies for CuteMarkEd sudo apt-get install libqt5webkit5-dev qttools5-dev-tools qt5-default discount libmarkdown2-dev libhunspell-dev #Compile and install CuteMarkEd qmake CuteMarkEd.pro cd CuteMarkEd/ qmake CuteMarkEd.pro make echo "A Qt-based Markdown editor with live HTML preview and syntax highlighting of markdown document." > description-pak sudo checkinstall --requires "libqt5webkit5, libmarkdown2, libhunspell-1.3-0, discount" sudo ln -s /usr/lib/x86_64-linux-gnu/qt5/bin/cutemarked /usr/local/bin/ sudo mkdir -p /usr/local/share/icons sudo cp app/icons/scalable/cutemarked.svg /usr/local/share/icons/cutemarked.svg sudo apt-get install fcitx-libs-qt5 Now there is a bug in the tool which makes the Gantt charts appear as monochrome but fear not for there is a workaround for it.Once installed, open CuteMarkEd and add a snippet in the tool to ensure Gantt charts display properly. Steps below: Enable diagram support by clicking Extras->Options->Diagram Support Add the snippet for quick creation by clicking Extras->Options->Snippets->Add Then type ~~~gantt and in description something to the effect of Adds the codeblock for mermaid with the necessary javascript Now in the snippet box add the following code. To invoke the snippet simply type in editor ~~~gantt followed by pressing the Ctrl+Space keys. ~~~mermaid gantt dateFormat YYYY-MM-DD title <Name of the project> %% <Name of Activity> : crit if critical else empty,done, active or empty, reference name or empty, Start Date or dependency, End Date or Duration section Phase 1 Name Activity 1 : done, des1, 2017-01-06, 2017-01-08 Activity 2 : active, des2, 2017-01-09, 2017-01-12 Activity 3 : des3, 2017-01-12, 5d Activity 4 : des4, after des3, 5d section Phase 2 Name Activity 5 : crit, done, 2017-01-06, 24h Activity 6 : crit, done, after des1, 2d Activity 7 : crit, active, 3d Activity 8 : crit, 5d Activity 9 : 2d Activity 10 : 1d section Phase 3 Name Activity 11 : active, a1, after des1, 3d Activity 12 : after a1 , 20h Activity 13 : doc1, after a1 , 48h section Phase 4 Name Activity 12 : after doc1, 3d Activity 15 : 20h Activity 16 : 48h ~~~ <script> mermaid.ganttConfig = { titleTopMargin:25, barHeight:20, barGap:4, topPadding:50, sidePadding:100, gridLineStartPadding:35, fontSize:11, numberSectionStyles:3, axisFormatter: [ // Within a day ["%I:%M", function (d) { return d.getHours(); }], // Monday a week ["w. %U", function (d) { return d.getDay() == 1; }], // Day within a week (not monday) ["%a %d", function (d) { return d.getDay() && d.getDate() != 1; }], // within a month ["%b %d", function (d) { return d.getDate() != 1; }], // Month ["%m-%y", function (d) { return d.getMonth(); }] ] }; </script> This will then show in the preview pane following Gantt Chart and we can edit, add and modify the data as per the requirements: TIP: You can make as many snippets as you want and for the simple solution that I mentioned right at the top, I made one snippet called dategantt replacing the code between line 3 to line 29 of the snippet above dateFormat DD/MM/YY title Project Name Section Pre-condition Activity 1 :21/12/16, 22/12/16 Activity 2 :21/12/16, 22/12/16 Activity 3 :16/01/17, 02/02/17 Activity 4 :01/02/17, 02/02/17 Section Kick-off Activity 5 :01/02/17, 03/02/17 Activity 6 :01/02/17, 03/02/17 Project Initiated :01/02/17, 03/02/17 Section Tech Design Technical Design :crit, active, T1, 06/02/17, 21/03/17 Section Delivery Activity 7 :06/02/17, 10/02/17 Activity 8 :10/02/17, 14/02/17 Order :15/02/17, 14/03/17 Deployment :crit, 15/03/17, 21/03/17 Activity 9 :crit,T2, after T1, 23/03/17 Project Close-Down :after T2, 24/03/17 Once done, just type dategantt followed by ctrl+space and you will have the framework to enter activities, start dates and end dates. Gantt Chart will be ready just like the one as cover image of this post right at the top !!! Install Mermaid CLI One of the drawbacks of the CuteMarkEd is that the pdf export there just does not work and you will need to rely on a screenshot. Now if the Gantt chart is really huge a screen shot wont cut it and mermaid does offer the ability to generate svg file for your effort. It is ofcourse a command line tool but is actually fairly easy to use once installed. #check if nodejs is installed. If command below results in nothing then you need to install nodejs nodejs -v # Instal nodejs sudo apt install nodejs #On Ubuntu there is some link issue where node is #referenced as nodejs which results in issues #while installing npm modules. This can be avoided #by creating a symlink using following command. sudo ln -s /usr/bin/nodejs /usr/bin/node #Install npm sudo apt install npm #In order to install npm modules without sudo, #As explained in one of [my previous posts](http://mgw.dumatics.com/ghost-on-fedora-24/#step3installnpmmodules), #it requires fixing the permissions using following steps. #This needs to be done only once so if you have #done this in past, then there is no need to repeat. mkdir ~/.npm-global npm config set prefix '~/.npm-global' nano ~/.profile source ~/.profile #Install Mermaid and phantomjs on which mermaid depends. npm install -g phantomjs npm install -g mermaid #Check if mermaid is installed by issuing the command mermaid --h #Generate a png using following command mermaid -p path/to/markdown file with .md or .mmd extension. Install Markdown-plus MarkdownPlus is a good markdown editor and can be used on their hosted solution or for offline use it can be installed as a local copy and accessed from the browser by pointing the browser to the index.html. The bug from CuteMarkEd is not present here. To access offline, you can clone it from github using following command. git clone --recursive https://github.com/tylingsoft/markdown-plus.git Then open the folder markdown-plus and right click on the index.html file and open it using your browser of choice. Alternatively, in the browser enter file:///home/path/to/markdown-plus//index.html. Mermaid Live Editor While Markdown Plus is quite a versatile browser based editor, I did not like the fact that there is no easy way to save the file you have created and all I could work out was that you will have to copy paste your text and save it using another text editor. I felt, for this reason that the Mermaid Live editor was better compared to this option and the live editor is quite basic to be honest and can't be used offline.

Markdown and Gantt Charts

For a fairly long time, I have been looking for a simple markdown type of solution to be able to quickly draw Gantt charts but never came across what one would call a quick option. It has always been an involved process. To my simplistic mind, a simple solution would
I have been with PlusNet for over two years now and am a happy camper as far as fiber optic broadband is concerned but as I am no longer on a broadband contract with PlusNet and had no intention of going on one, so the only way I could get a change to my ageing router was by purchasing a new one. Hence I started reading about my options and soon enough realised that an old router can be given new lease of life using DD-WRT. Equally soon-ish I also realised that the router from PlusNet - TG582n - is quite rubbish and does not play nice with any of the open source firmwares. So I figured that if I have to just play around a bit, I might as well start with something cheaper and cheaper is what I found is the TP-Link router TL-WR841n at just £16.00. You can't get any cheaper than that in my opinion. OK, so now that we have established that I am cheap and my new router is cheap, let's move on to interesting stuff. I had read that TP-Link router and specifically TL-WR841n plays nicely with DD-WRT but it was only after I had my new toy did I realise that these things also come in hardware version and while interwebs is filled with instructions on installing DD-WRT for upto v9, when it comes to v11 in Europe, it can be a bit tricky to proceed. There are some instructions in forums but nothing that walks one end to end hence this post. There are two ways to ensure that the DD-WRT firmware gets flashed on the router: Apply Unlocked stock firmware - This is the one I used and to use this I downloaded the modified firmware from NeDark that he has provided in a post on the OpenWRT forum here Using TFTP server - This is considered to be a safe approach because you do not have to use any modded version of stock firmware to apply it. However, if like me you are anyway going to flash it with DD-WRT, I feel it's a bit of pain that can be avoided as it involves setting up TFTP server and making your router to connect to this router can take some time and effort. It is explained here. Right, so assuming you want to go with the first and easier approach, first you need to download the modded firmware from NeDark. He has uploaded it on his dropbox link and I have also uploaded a copy of this firmware here. I recommend that you download all the three files from my folder on Mediafire using the link below but if you would much rather download directly from DD-WRT, then the links for rest of the two files that I used are also in references and below. Assuming that now you have all the three files safely downloaded to you computer we just follow the simple steps below: Connect the power supply to the TP-Link router and switch it on. Connect the ethernet cable in one of the yellow LAN slots of the router. Switch-off the wifi on your computer and connect the other end of the ethernet cable to the ethernet port of your computer. Once the ethernet connection on your laptop is established, open a browser and type 192.168.0.1 and press enter. You will be presented with TP-LINK admin interface. Login using the credentials username: admin; password: admin. On left hand navigation locate and click on System Tools and then on expanded menu click on Firmware Upgrade Now click on Browse button and select the file from NeDARK - wr841n(EU)_v11_150616.bin from your downloaded folder. Click on Upgrade button. It will take roughly 30 to 40 seconds and router will reboot. Refresh the browser screen and you will once again be presented with TP-LINK admin interface. Once again login using the credentials username: admin; password: admin. On left hand navigation locate and click on System Tools and then on expanded menu click on Firmware Upgrade Now click on Browse button and select the file factory-to-ddwrt.bin. Click on Upgrade button. It will take roughly 30 to 40 seconds and router will reboot. Disconnect the ethernet cable from Laptop and reboot the laptop - This isn't always required but just to be safe. Reconnect the ethernet cable to the laptop. Make sure that wifi is switched off on the laptop. Once the ethernet connection on your laptop is established, open a browser and type 192.168.1.1 and press enter. <-- Notice the different IP than what was used in step 4. If all has gone well until now you will be greeted with DD-WRT login interface and will actually be asked to change the password. After providing the password, navigate to tab Administration and then sub-tab named Firmware upgrade. Click on Browse' and this time selecttl-wr841nd-webflash.bin` and Click upgrade. This will take 40 seconds or so and your router has now been liberated. This is it for flashing TP-LINK TL-WR841N v11 router with DD-WRT. I will be writing more about how to configure DD-WRT to work with Plusnet fiber optic broadband and to play nice with NEST so stay tuned if this interests you. I made fiber optic broadband work with no fuss but with NEST there were some issues basically down to auto setting changing to channel 13. Making NEST play nice with DD-WRT The issue was that NEST would suddenly drop internet connection and then not identify the SSID for my router. The SSID just won't appear in the list of available wireless networks. NEST apparently does not like channel 13, possibly even Channel 11 and 12. Changing the channel to any of the single digit (1 - 9) works well. In addition giving a static IP for NEST MAC seems to have resolved any network drops whatsoever. Under Wireless Setting, I also changed the Beacon Interval to 211. Under Administration tab -> Management -> IP Filter Settings, I changed the TCP timeout to 1800 and UDP timeout to 3600. Configure router for PlusNet Fiber Optic Broadband For configuring PlusNet fiber optic broadband, the settings I used are as below: Setup -> Basic Setup Setup -> DDNS Wireless -> Basic Settings Wireless -> Wireless Security Administration -> Management Administration -> Commands Add the following in the startup commands # Fix lan port communication 841 v7, v9, v11 swconfig dev eth0 set enable_vlan 1 swconfig dev eth0 set apply as shown below: Above basic setting ensures that PlusNet fiber optic broadband works perfectly fine. REFERENCES: https://www.quora.com/Is-the-TP-Link-TL-WR841n-v11-router-supported-by-DD-WRT ↩ https://www.mediafire.com/folder/q56dcdecfh3v1/Router_Firmware ↩ http://download1.dd-wrt.com/dd-wrtv2/downloads/betas/2016/12-15-2016-r30949/tplink_tl-wr841ndv11/factory-to-ddwrt.bin ↩ http://download1.dd-wrt.com/dd-wrtv2/downloads/betas/2016/12-15-2016-r30949/tplink_tl-wr841ndv11/tl-wr841nd-webflash.bin ↩

DD-WRT firmware on TP-LINK TL-WR841N v11

I have been with PlusNet for over two years now and am a happy camper as far as fiber optic broadband is concerned but as I am no longer on a broadband contract with PlusNet and had no intention of going on one, so the only way I could get
While renewing my LetsEncrypt certificate, I found myself in a strange situation where the certbot won't run asking me to update pip and then each time I tried updating pip it failed with the error "error: command 'x86_64-linux-gnu-gcc' failed with exit status 4". It turns out that this happens due to low memory and with my digitalocean droplet being the cheapest one this was bound to happen sooner rather than later. Fortunately there is a way around it as explained below. Use of following commands will ensure that the swap file is created which in turn will help avoid the "error: command 'x86_64-linux-gnu-gcc' failed with exit status 4". Following commands will create a swap file: sudo dd if=/dev/zero of=/swapfile1 bs=1024 count=524288 sudo mkswap /swapfile1 sudo chown root:root /swapfile1 sudo chmod 0600 /swapfile1 sudo swapon /swapfile1 The swap file will now be activated but will be gone after the reboot. It can be reactivated using the last command (I hope - know so as I have now tried it). Anyway, after creating the swapfile, you will be able to upgrade pip without the aforementioned error. :) Update: 02/03/2017 I ran into memory issues yet again and I thought instead of increasing the memory for swapfile1, what if I can create another swapfile. I tried this and it works. Infact I felt quite nice uncovering a concept of multiple swapfiles purely based on my whim ;). All I really had to do was repeat above code replacing swapfile1 with swapfile2 and I had two swapfiles working together increasing available memory for my server. sudo dd if=/dev/zero of=/swapfile2 bs=1024 count=524288 sudo mkswap /swapfile2 sudo chown root:root /swapfile2 sudo chmod 0600 /swapfile2 sudo swapon /swapfile2 Thing is after it worked I was a bit intrigued by the concept and read a bit more on swapon / swapoff and few useful commands are listed below: # To enable all swapfiles swapon -a # To disable all swapfiles swapoff -a # To see all available swapfiles swapon -s # To enable a particular swapfile swapon <filename>

Swap File to create extra memory

While renewing my LetsEncrypt certificate, I found myself in a strange situation where the certbot won't run asking me to update pip and then each time I tried updating pip it failed with the error "error: command 'x86_64-linux-gnu-gcc' failed with exit status 4". It turns out that this happens
I was a super excited owner of Note 7 in September this year and then in few days the happiness started disappearing as the news of exploding Note 7 started appearing all over the internet. Then came the notice to exchange the Note 7 which I dutifully did and assured that nothing will now go wrong I started enjoying that gem of a device. Alas, it was not to be and the device was recalled for good. Being a user of Note devices for so long and yet unable to continue with my old Note 3, I decided to go for some interim device - you know until Samsung decides to get the act right and bring the next Note device to the market. After going through a number of possible options ranging from Note 7's close cousin Galaxy S7 edge+ all the way to newly released Pixel, I actually settled for OnePlus 3. It was not a gamble actually as my wife is already using it and is quite pleased with it's performance and the price is just right for this to qualify as the interim phone. Anyway, so I ordered and waited because there was a good 4 week wait period. The ordering and delivery all went as planned while in the meantime I was back with my trusty Note 3. OnePlus 3 arrived and I set it up to my taste and my oh my what an experience. Apart from Stylus it was lacking nothing and is very smooth, very light and camera quality is very good as well - not as good as Note 7 but definitely better than Note 3. I have now been with this device for just over a week and although I miss the S-Pen, I am very happy with the device in general and it's battery life in particular. I have listed below the things that I like and the things I hope it had: Features I Loved: Battery life Superfast Chargingwith Dash Charger Display and inbuilt Night mode Ringer Switch Inbuilt Colour control for LED Notification Smooth minimal interface No bloatware Fingerprint Scanner doubles as Home button Gesture support for flash light Ability to swap Capacitive button functionality Dual Sim Card capability - Allows me to carry one phone for both work and personal numbers. Sure all of the above can be pretty similar on all high end handsets but what makes it unique for OnePlus 3 is the price point of £329. That price is unbeatable and the phone, in my humble opinion, must be the first choice for anyone who isn't fussed about a stylus. There can be a comparison between camera results where Samsung outperforms in my experience but only slightly and still the photo quality from OnePlus 3 is definitely very good second only to Samsung and no other. Wishlist Functional Stylus (Frankly no other manufacturer is tapping on this market. God knows why?) Note 7 had a good integration of Fingerprint Scanner with browser to login to various sites. I miss that on OnePlus 3. External Memory Card slot. Here's hoping that OnePlus 3 team will listen to my wishlist :).

Note 7 to OnePlus 3

I was a super excited owner of Note 7 in September this year and then in few days the happiness started disappearing as the news of exploding Note 7 started appearing all over the internet. Then came the notice to exchange the Note 7 which I dutifully did and assured