Sunday, 10 February 2019

Programming on Windows

During the last four years, until the early part of 2018, I worked on a MacBook. Sometime in the second quarter of last year, I shifted to a Windows 10 laptop. The transition has been quite smooth and delightful.


There were two Rails applications that I had to write and maintain. The first application, let's call it webapp-1, was coded by me in 2016 using Ruby 2.3.1 p112 and Rails 4.2.6. The second application, hereafter referred to as webapp-2, is a new application that I had to write from scratch, so I chose the latest versions: Ruby 2.5.3, Rails 5.2.1.

For both these applications, the database was MySQL, and I decided to install the latest version, i.e., 8 running on Windows. The MySQL installer tools make the installation and configuration very easy and I could bring up MySQL quickly.

I started setting up the Rails environment for webapp-2 first. The installation program for windows that I downloaded was rubyinstaller-devkit-2.5.3-1-x64.exe. I ran it, selected MSYS2 and MINGW development toolchain option and the installation went through smoothly. I installed rails gem with the following command
> gem install rails --version 5.2.1

But then, when I started the rails server, I ran into a library issue. In the browser, I accessed localhost:3000 and I got a nasty looking error:
Authentication plugin 'caching_sha2_password' cannot be loaded: The specified module could not be found.

I had installed MySQL with SHA-256 password encryption option. The mysql2 gem on Windows does not have the required plugin. This problem could be resolved by switching to mysql_native_password. For this, I needed to do two steps: a) change the value of default_authentication_plugin to mysql_native_password in the file my.ini. b) In MySQL Workbench, run the command - ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'my_password';

But then I thought what's the point of using the latest version of MySQL but not its latest security feature? I raised an issue1 on github. But then, I realized that the gem wouldn't be updated soon and also came to understand that the mysql2 gem on Linux did not have this issue. So, what to do?

It was time for Ubuntu on Windows.

I found an article2 explaining how to installing Rails on Ubuntu on Windows. Though this article instructs to start with Developer mode in Windows settings, I didn't have to do that. Ubuntu is now an app on the Microsoft store and you just have to install that app.

In the past, I'd used rvm (on my Ubuntu Linux personal laptop) to manage my Rails versions. Therefore, I tried installing rvm first. However, I ran into a couple of errors and I switched to installing rbenv which is recommended by the article. Thereafter, the process went without a hitch.

The summary of my current programming environment is: I start MySQL on Windows. My code is in a folder called "Code" in the D drive and I edit the source code as Windows files in my IDE. In the Ubuntu console, my folder is accessible as /mnt/d/Code. I go to my project folder and run rails server to start my application.

Well, I have captured the series of commands and some notes of the whole installation process, in the following gist:

Windows has some pretty good package managers. I use Chocolatey. In fact, it was one of the first programs I'd installed after I got my laptop. After installing it, it was pretty much choco install this and choco install that to get most of the tools I need.

My most frequently used tool set on Windows consists of: Outlook, Chrome, Trello, Evernote, Notepad++, Eclipse (for Java programming), VS Code (for all other programming languages), Write!, FileZilla, Cmder and Ubuntu. Apart from these, I love the Win key-D combination to go straight to the Desktop, Fn-F11 is really not quite the same thing. Anything I need is available with just the Win key, there is no need for the extra tap on the space bar.

I am loving programming on Windows and wish to have a productive year ahead. Yeah I know it's a bit late, but might as well better late than never: here's wishing you all a prosperous and productive 2019. Happy New Year !

References:
  1. https://github.com/brianmario/mysql2/issues/1015
  2. https://gorails.com/setup/windows/10

Friday, 27 October 2017

Easy Image Slider

I needed a image slider for one of my web pages. The bootstrap template that I was using also provided a slider component but needed a lot of tweaking to suit my page.

When I googled, I chanced upon imageslidermaker.com. It was simple and very easy to use. All you need to do is select the slider configuration on the screen and with one click, the site will generate the css, js and html files that you can download as a zip file.

The generated slider code stands on its own and does not intrude into the existing style, script and mark up code. You can easily customize the css. For example, I made my own style for the image caption as given below:
#my-slider .ism-caption-3 {
    font-size: 1.75em;
    font-family: sans-serif;
    position: absolute; top: 20%;
    left: 10%;
    border-radius: 4px;
    border: none;
    color:  #FFFFFF;
    text-align: left;
}
Try it, you will like it.

Friday, 29 September 2017

Daughters Of India

This post is not about feminist movements in India or any such similar topic; rather it's about using Python code for applying basic NLP (Natural Language Processing) techniques on tweets.

Friday, 8 September 2017

Ideas From Another Field

Applying concepts from one field or a book in another field has been a common pattern in modern technological development. The spirit of antifragile, a recently coined word, has found its way in the implementation of microservices. In the quest to make software programs antifragile, the way forward is to build intelligence into them. A couple of other examples are: i) The law of diminishing returns from economics which applied to parallel computing becomes Amdahl's Law. ii) I surmise that the Agile board in the Scrum methodology is the application of the Hawthorne Effect. Cross-pollination of ideas is one of the mechanisms of innovation. And, as we found out recently, learning transfer is the way Elon Musk follows to become such a prolific technocrat and businessman.
My essay ends here.

Friday, 11 August 2017

I Dare You Not To Fall In Love

On the best part of using Ruby on Rails for software development, thus spake its creator David Hansson:
You get to use Ruby, which, even in a world that has rediscovered the benefits of functional programming and immutability, remains the most extraordinarily beautiful and luxurious language I’ve yet to encounter. Just look at some code. I dare you not to fall in love.[1]
Well, this is my exact opinion of Ruby, my most favourite programming language but I couldn't have articulated it any better than Hansson.

Friday, 2 June 2017

Applied Rails : Gems I Use

In this article, I discuss key gems that I have used in my Rails application. For each gem, I state what it is used for, a brief description of how I used it and the code snippet(s) pertaining to my use case.

Friday, 12 May 2017

Book Review : The Rise Of The Robots

The technology world faces new trends frequently. New technologies typically promise to get things done faster, reduce costs, and open new market segments, thus improving the financials of a lot of firms. From Service-oriented Architecture to mobile and cloud computing, all of them stake their claim to deliver these benefits.

However, the advent of Artificial Intelligence (AI) will impact the world economy in a way that no technology in the past was able to. This is the core thesis of Martin Ford’s 2015 book, 'The Rise of the Robots', sub-titled 'Technology and the Threat of Mass Unemployment.' If AI can unleash a tsunami of unemployment, how should America deal with it?