Toggl’s “Building a Horse with Programming” comic explained

If you don’t know what this is about, you should first go and check it out.

So, C++ is, for me at least, an intolerable programming language. Everything from the code to the resultant program tends to be as ugly as it gets. More than half the time it feels like it was hacked-together to include everything. However, it has been around for a very long time and you can use it to do just about anything that you could want to do with a programming language. Only, the experience and the result may not exactly be great.

Then we have Java. The main problem with Java is that for a language that aims to be useful for all sorts of applications on all platforms, it’s missing a lot of features that are commonly used by full-stack developers. Very often, when writing programs in Java, programmers end up spending more time than they need to creating new types and methods so that they can use them in the program that they actually set out to write.

Ever since npm and nodejs gained popularity, JavaScript has become one of the world’s most widely used languages and npm is probably the most used package manager of them all. And the thing about Javascript programmers is that they use a lot of external libraries and packages and every once in a while, they add their own package to the global repository just to get a kick out of it. By now there are probably more packages in npm than there are libraries for any other language out there and when you are a JavaScript developer, you really have use them if you want to get any work done. The pinked “Backbone” and “Angular” are references to Backbone.js and Angular.js, two popular JS frameworks.

NoSQL refers to database systems that don’t use SQL and are non-relational. An example is MongoDB, which stores JSON objects grouped into collections. The joke is that the non-relational model doesn’t always expose enough information for you to be able to access your objects without using the abstract api.

COBOL? Well, I guess no one entirely gets it except for its creator.

Lisp has a lot of parentheses. Just google sample codes for lisp and you’d know.

C# is a fairly complete and tolerable language. The problem? Microsoft. Windows. The thing about the costume is that C# is basically Java in a costume (it closely resembles Java in terms of syntax and semantics.) The camel is basically the windows environment. Basically, it means that C# programs don’t always work as intended if not running on Windows.

Assembly doesn’t really offer a lot of language features. There’s a basic set of operations that have to be used for everything. But coding something in such a low level language means you get control over aspects that most languages abstract over. So you can make a really efficient program, hence, the thing about running.

Everyone hates PHP. They say it’s a terrible and unsafe language and has unpredictable behavior. I personally have reasons to really like PHP but I will still go ahead and tell you that most good posts on the subject target aspects of the language that really do suck so yeah some of the hate is justified.

 

SQL Server screwups and how to fix them.

So recently I installed Visual Studio 2017 on a laptop and I installed it with only the ASP.NET and WinForms features. I was working on a webapp and initializing the database when I realized that VS was completely unable to connect to the database. I opened the “SQL Server Object Explorer” and tried to manually connect to the MSSQLLocalDB instance and I got this error.

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 – Local Database Runtime error occurred. Error occurred during LocalDB instance startup: SQL Server process failed to start.) (Microsoft SQL Server)

I tried to start the service from the CMD and I kept on getting similar errors. Eventually, I concluded that the installation was corrupted and therefore tried reinstalling LocalDB. Guess what? It got me past this error but introduced me to another. It was something like this.

CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file ‘c:\Users\AnasDatabaseName-asdf5sdfasd5fs5dfs5f.mdf’.

This time, the CREATE Database command was failing because it was trying to create and MDF file in my “Users” folder. I checked the default location for the databases and it was in a sub-sub-sub-sub-folder inside AppData. A bit of Googling told me that this was actually a bug in the program itself and had been fixed in a recent update. So I just downloaded the latest Cumulative Update from the Microsoft site and it did the trick.

 

Angular vs React vs Vue.JS

This is the shortest and most effective comparison that aims to make the decision making process easier.

Angular: 

Pros:

  • The oldest and therefore very mature.
  • A complete framework in itself and ideal for large projects.
  • The MEAN stack remains, to date, one of the most popular stacks for web-development so finding jobs is never tough for Angular developers.
  • With NativeScript, you can use it to develop smartphone apps.

Cons:

  • If you don’t know, don’t like or don’t want to learn TypeScript, I would suggest staying away from it because the current releases are TypeScript based.
  • Packed with features, it’s a huge framework and therefore takes a fair amount of time to learn and master.

React:

Pros:

  • Been around for a fair amount of time and therefore can be said to be just as mature as Angular.
  • Smaller than Angular and therefore easier to learn.
  • Just as popular, if not more, and therefore has a well-developed community.
  • Just as many jobs out there for it as for Angular.
  • React Native allows for it to be used to make Android apps.

Cons:

  • You will have to learn JSX. Basically the idea is that in ReactJS, you try to maximize your use of JS and minimize your use of HTML. JSX kinda merges both. Obviously this adds to the learning curve.
  • Not a complete framework. React Developers almost always use Redux or some other flux implementation for state management. Code often becomes a real mess with large projects.

Vue.JS:

Pros:

  • Has just as many features as React, if not more.
  • Small enough for you to be able to learn it in a single day.
  • Great for small projects.
  • Gaining popularity real quick.
  • Resembles the original Angular.JS so if you are familiar with it, you’d love Vue.
  • Unlike React, with Vue, the goal is to maximize the use of HTML and minimize the use of JS.
  • Although not a complete framework, it comes with it’s own router and flux implementation, that, although independent projects, offer seamless integration with Vue itself.

Cons:

  • Relatively new and therefore has a small community and fewer jobs are available.
  • NativeScript has a plugin for Vue support but it not supposed to be ready for development yet. Although, it seemed pretty functional when I tried it.
 

Rewriting Legacy Code

I once wrote an answer on Quora about the improbability of a programming language to completely die out once it has gained popularity. The idea, not so original, was that there are two factors preventing a language from dying:

  1. A significant amount of code is written in it and a significant amount of people or other code depend strongly on it. An example is Linux. Now Linux has always been C and always will be. As long as Linux exists, it would be impossible for C to die out.
  2. Everyone knows about it. The problem with a programming language being popular enough for it’s existence to be common knowledge is that there will always be people who’ll be fond of it and would want it to never die out. The best example would be Richard Eng, the smalltalk evangelist who has grown more popular than the language itself and likes to call himself Mr. Smalltalk.

This post is about the first reason. C, PHP and JavaScript are three of the most popular and most hated languages that are getting closer and closer to being about as old as time itself. For my own reasons, I both like and dislike the 3 and also rely a lot on them. Let’s assume everyone agrees to killing all 3 of them. Now the problem is that C is:

  1. The language Linux is written in.
  2. The language most programmers start with. (Often this is because universities prefer to teach it in the earlier semesters.)
  3. More or less the only mature language that has the least amount of abstraction that one could ask for except for C++, which is a mess and an offspring of C itself and therefore not worth talking about in this post.

… 

 

Comparing strings with “==” operator vs “.equals” method [Java]

During lunch, I was reflecting on that day when my programming teacher asked me to come forward and teach “bitwise” operations to the whole class, and I remembered how, in my attempt to explain to them the basic difference between a regular “OR” and a bitwise “OR”, I had talked about value comparison being different from a bitwise comparison. Then I began to wonder. A bitwise operation on machine level is fairly simple to understand, but what about value comparison? What is it that happens at machine level when you check if two integer values are equal?

As I began my search for the answer, I pinged Vladislav Zorov, my mentor and friend, and asked him. He said that compilers mostly just subtract the memory addresses of the two objects being compared and returns true if the difference is zero i.e. if they are literally the same object. I couldn’t agree with this so I argued against it. I said that it is possible for two variables to point to identical objects without pointing to the same object and so I set out to prove it.

I wrote a very simple program:

import java.util.Scanner;
public class HelloWorld {
public static void main(String []args){
// Created two strings using the same literal and an array with the second index set using that literal.
String x = “abcd”;
String y = “abcd”;
String[] z = {“asafaf”,”abcd”};

// Printing addresses of all 3.
System.out.println(Integer.toHexString(x.hashCode()));
System.out.println(Integer.toHexString(y.hashCode()));
System.out.println(Integer.toHexString(z[1].hashCode()));

// Checking to see if the equality symbol works on these
if(x == z[1] && x==y && y==z[1])
System.out.println(“== works on the 3”);

// Comparing the 3 using the equals method which will, obviously, work.
if(x.equals(z[1]) && x.equals(y) && y.equals(z[1]))
System.out.println(“equals method works on the 3”);

// Creating Scanner object to read from stdin.
Scanner input = new Scanner(System.in);

// Taking two strings as input. Will test with
// 1. Two different strings
// 2. Identical strings
// 3. “abcd” for both
String j = input.next();
String k = input.next();

//printing their addresses
System.out.println(Integer.toHexString(k.hashCode()));
System.out.println(Integer.toHexString(j.hashCode()));

// Testing both comparisons
if(j==k)
System.out.println(“== working on input strings”);
if(k.equals(j))
System.out.println(“equals working on input strings”);

// Initializing a string identical to x,y,z[1] but with the new keyword
String a = new String(“abcd”);
// Printing its address
System.out.println(Integer.toHexString(a.hashCode()));
if(a==x || a==y || a== z[1])
System.out.println(“== working with new keyword”);
if(a.equals(x))
System.out.println(“equals method working with new keyword”);
}
}

If you run it, you’ll see that its output shows that all strings that have the same value point to the same address regardless of how they’re initialized. But the equality symbol only works when two strings have been created with the same literal. The fact that we’ve now proven that identical strings in Java do have the same memory address does perhaps imply that comparison is done simply by comparing addresses but then what about the equality symbol? Well, I’ll update this post when I find out.

 

How GoDaddy robbed me.

Humble request to all readers: Share this post.

I really want to keep this as short as I can and address only the primary issue. For those who don’t know, GoDaddy is one of the most popular domain registrar’s in the market and I started using it a couple of years back as a means for getting rid of my local registrar who had been screwing up routinely in a most inefficient way.

Abstract: Lately, they have not only made a few irrational and immoral decisions, but they also robbed me of a rather large sum of money and then messed up my order completely. In short, I paid thrice for the same order and I didn’t even get what I ordered. Furthermore, somehow the same domain was purchased twice using my account and I have absolutely no idea how it’s even possible. … 

 

What the hell?

So I was minding my own business in my humble abode when I receive an email. A quick look at my phone’s notification bar tells me that it was from the admissions counselor (, let’s call her Daisy,) of a college that had accepted me. I wasn’t at all surprised because the decision day for that college had just passed and I hadn’t shared mine at all.

The email said “Daisy has shared a document with you.” And had a button that said:Open in Docs.

Like a dumbass, I clicked on it. I did wonder why she’d share a document with me and I did, kinda, wonder why it didn’t look like the average Google Doc invitation, but I was on my phone and I chose to overlook it.

Then I land on a page that asks me if I want Google Drive to have access to my email account. It asked for permissions like “Edit, delete and create emails.” I was certain, by this point, that something was not right. And I just allowed it. You know why? Cause the goddamned address bar clearly showed that I was still on Google and still on https. I was redirected and then it appeared to be completing a request and loading something and after waiting for a few minutes, I realized what I had done.

Now I noticed another weird email, and it said “Anas Khan has shared a document with you.” That was it. Now I realized what those permissions were for. I checked the sent mail and realized that this shit had forwarded itself to “[email protected]” and that email was BCC’d to virtually every email address that I had ever communicated with.

Well, kinda screwed up. But I have to say this: It was a clever scam.

 

The Dilemma of Programming Languages

So, I’ve been up and laptop-ing for the last two hours or so, and all I’ve been doing is reading one article after another centered on programming languages. A good fraction of those articles lashed on how Javascript sucks. It’s been a lot of continuous reading, all thanks to catchy links located throughout the articles, and at any given time there have been at least 7 tabs (with articles) open at all times. Even as of now, there are exactly seven other tabs, besides Facebook, open in my browser.

It all started when I, scrolling through my news feed, out of sheer boredom, landed on a post by Richard Eng, an evangelist for SmallTalk whom I first came across on Quora, and while reading, I clicked on some other links and opened them in new tabs, and then the process repeated itself. The more I read, the clearer became Eng’s views on the different languages. It was clear that he hates JavaScript, and just the first part of this post by him shows that he definitely has a point.

While going through his list of his JavaScript alternatives, which are all basically Transpilers, I also discovered Brython, which is basically Python running in JavaScript’s place as the client-side scripting language. It’s pretty cool actually, although apparently the code is transpiled from Python to JS during runtime and that’s gotta take a toll on the performance.

Also, like countless other people, Mr. Smalltalk was kind enough to tell us that PHP is one of the three languages he can’t stand. While I agree that JS deserves to be on that list, my love for and comfort with PHP is too strong. It hurts when people constantly tell me that PHP sucks, and that it shouldn’t be used on any serious projects. Maybe they are right, maybe they aren’t, but I do believe that PHP is going to be around for a long time.

While reading about the desire for improvements to JavaScript, I wondered about what would be the best way to work towards them. They can’t just change everything like Angular did with the 2.0, that could break the web. But if they offer backwards compatibility, it would just keep growing and ultimately become a huge confusing mess.
I guess that it’s fairly safe to say, that with programming languages, it’s important to make the correct decisions during the initial stages of development.

You might be wondering what the point of this article is, or what exactly is the actual “dilemma.” To be honest, there isn’t a point. I’m just thinking out loud. Incoming opinions lead to indecisiveness, which in turn results in time going wasted.

 

Contextmenus.js

Purely Javascript based solution allowing for easy creation of right-click context menus. Browse the code on GitHub. Demo

So, Haider posted on his Facebook timeline, a link to his then newly setup github repo which he had named “rightclick.js.” It was pretty clear what it was about so I gave his code a look. He is using JQuery, and (for some reason unclear to me,) NodeJS.

This morning, I decided to make my own in pure Javascript. I started around afternoon and got done with it a couple of hours ago. I wanted to call it contextmenu.js but there already exists a script by that name, and thus, out of respect, I renamed mine to contextmenus.js. The code happens to be a couple of files that together take up a total of 1812 Bytes of disk space. Everything  that you need to know, in order to get it to work for you, is explained in the README.md on the GitHub page.

 

Progresive Web Apps

You are using a computing device, be it a smartphone, a tablet, a desktop computer. It’s new, shiny, with little or no applications installed, apart from the bloatware that the manufacturer could have generously shipped with it. You fire up Facebook in a web browser, like a couple of pictures, post a status, have a small chat with a friend, and then after a while, you close the tab and lock your phone. After a while you do it again, and this time, you spend a whole hour scrolling through the news feed, and then once again you close the tab, and lock your device.

Now while it’s locked, and still connected, your device makes a decision. Assuming that you like Facebook, it adds a Facebook icon to your homescreen, or your app-drawer, for easy access to facebook.com. So the next time you unlock your iPhone, you simply tap on that icon, and it opens facebook.com in your default web browser. You love it.. It’s just a simple link, but it already feels great, and it could be better. Soon enough, after another day’s usage of the site, you notice that tapping the app icon no longer opens a browser window with facebook.com. Instead, you get a window solely running Facebook like it’s a standalone native application for your operating-system. … 

 

Alexarank.io

On January 3rd, I launched a tool, that’s hosted at; yep, that’s right. You guessed it: alexarank.io. What the tool does, is pretty simple. It tracks the global Alexa ranks for domains, and shows the change over time in a chart. It’s not exactly tracking every damn domain on the web, but nothing prevents it from doing so. Except that someone, and I mean anyone who cares enough, has to submit the domain once, and that very instant, the tool would start tracking the domain.

On December 27th, Amin messaged me and shared his desire for tool that would track changes in Alexa ranks for particular domains. On the slightest effort at googling, we both discovered a shitty tool that offered to do so at some price I didn’t even bother to remember. Alexa itself offers to do that for you, but they too, yep you guessed it, do it for a fee. So I say to Amin, we need to make a free alternative, and we immediately start concepting, and after a while we started playing with code. Within the next few days we had a working buggy prototype up, but it was uglier than you could possibly imagine, so we fixed the bugs, and made it look presentable and on the 3rd day of 2016 we registered the domain and it was up.

 

Highlight menu link of the current page.

On some websites, regardless of whether or not they are wordpress or even PHP, the menu link for the page you are viewing gets highlighted or it becomes active. An example could be the 2014 theme for WordPress (see how, in the nav bar at the top, the link for home is green?) or css-tricks.com (link for the current page is orange.)

In static web pages, there could be more than one ways of doing this, and I’m not even gonna go there. But in dynamic websites, where there could be tons of pages with the same elements loaded, like the nav, the header, e.t.c. you can’t really change the attributes of a certain list item to suit a particular page.
Now the thing is, this isnt exactly rocket science.. Most good WordPress themes have this by default, but thanks to those few that don’t, I know that there’ll always be those who’d ditch a theme they spent ages styling on, simply because they’ll be tempted to use one that has it.

The day before I was modifying a theme, and I was almost completely done making it look like I wanted to, when I noticed that the css for :active state on the links didn’t apply. Of course that was stupid, no one really bothers with the active state anyway, they usually just define their own class.. After comparing the theme with another, and failing to find out how a general theme does it, I decided to code it in myself.

CSS-Tricks has this age old tutorial video  that shows a way to code it in yourself. Basically the idea is to parse the URL, and get the page request from the permalink. If you played the video, you can see how he got the page’s name and he applied it to the body as an id, and in his css he defined a style for body with ids matching the names of all his pages.

I however would do it slightly differently.. Just like he did, we get the request URL, get rid of slashes and question marsk (if any,) and apply it to a var ready to be echoed. But instead of applying and id to the body, and adding a comma separated “body#pagename” a number of times, we can define css for a particular class, like, for example “.current,” and add a script to the page, which gets the page’s name from the url, and finds the menu item with that name in it’s “title” attribute, and applies the “.current” class to it.

So all you gotta do is add the style for the .current class to the css file and then add the php from that css-tricks tutorial (the $page variable,)  to the header.php. And then you need to add a small Javascript script, that takes that $page var (don’t underestimate the power of <?php echo $page; ?>,) and applies the class to the corresponding menu link.

As a bonus, I will add below all the code you need to make this work.

<?php

$page = $_SERVER[‘REQUEST_URI’];
$page = str_replace(“?”,””,$page);
$page = str_replace(“/”,””,$page);
$page = str_replace(“.php”,””,$page);
$page = $page ? $page : “home”; ?>

Add this PHP at the very top of the header file.. before everything, and then, anywhere below below the nav markup, add this JS script:

<script>
nav = document.getElementsByClassName(“nav”)[0];
nav = nav.getElementsByTagName(“a”);
for(i=0;i<nav.length;i++){
if(nav[i].getAttribute(“title”).toLowerCase() == “<?php echo strtolower($page);?>”){
nav[i].setAttribute(“class”,”current”);
}}
</script>

You might have noticed that this only works if the container of the nav has a “.nav class to it. Even if it doesn’t that can simply be added, and if there’s a different class name you are inclined to use, then simply use it, or if there’s an id, replace the “getElementsByClassName” with  “getElementById.” But that wasn’t just it. Another prerequisite for it to work is for the tags in the nav to have title attributes. So yeah maybe I’m just wasting my time posting this. But hey! Whatever works, works.

 

Using two routers to extend a network – Part 2

The goal: Create two separate networks, each with its own router. Both routers will have different security and SSID, while the WAN settings of A are configured to connect to the internet while B, being a subnetwork of the first, will connect to the internet through it.

Now the thing is that the LAN and WAN IP addresses can not be in the same subnet, so here’s what I did. I changed the subnet of A from 255.255.255.0 to 255.255.0.0 .. Also, I changed to IP Adress to 192.168.1.1. That’s all the config you need to do in Router A, assuming it is already configured to connect to the internet.

Now get an Ethernet cable and plug one end of it into any of the LAN ports (some reccomend the first) in A, and the other end into the WAN port of B. Login to it’s portal.. yeah it’s at 192.168.0.1. Though I don’t see why dynamic shouldn’t  work, but since it didn’t for me, let’s assume it won’t work for anyone else. Select Static IP in the startup wizard and you’d be greeted by a number of blank input-boxes.  Fill them in as follows:

IP Address: 192.168.1.2

Subnet Mask: 255.255.255.0

Gateway: 192.168.1.1

Primary DNS Server: 192.168.1.1

That ought to do the trick. You might want to do a reboot, but that’s not always necessary.

 

Using two routers to extend a network – Part 1

Umm, yeah, so let’s get to it. What was the first interpretation? oh that’s right, Router B to act as a wireless access point for A.

So, A has an internet connection and B has to be connected to it via a cable and configured in such a manner that the connected devices automatically connect to either of the two devices with the best signal as you move about, and as B is acting as an access points, all data B receives and sends would of course need to be sent to and received from A. (Pardon me if something I’ve written doesn’t seem correct, I’m merely a noob and explaining in terms your grandma could understand.)

This was actually pretty simple, so I’d just list the steps leaving out the screenshots.

  1. Get an ethernet cable and insert one end of it into any LAN port on A, and the other end into the first LAN port of B. (actually I’m not sure if it has to be the first port or not.)
  2. Login to the web interface of B and set the SSID, i.e the name of the network, and the security settings of B to be the same as those of A. e.g. if A is called “narlges” and it’s using WPA, with passphrase “flutterwacken”, then you need to apply the same settings on B.
  3. Making sure that both A and B are in the same subnet, change the LAN IP adress of B to something other than that of A. So if the IP of A is 192.168.0.1, then you can set B to 192.168.0.X. Basically X can be any number between 0 and 255 except 1 as it is being used by A.
  4. Disable DHCP on B as it won’t be assigning IP addresses and all.
  5. Other wireless and radio settings like channel and all need to be the same too
  6. Reboot both routers?

And basically that’s it.

 

Using two routers to extend a network

I have recently been faced with this challenge, partly for learning, as it’s kind of an enthusiast thing and partly because I might actually need to to that in the near future. Since the title might seem a bit vague or ambigous to some, let me first make a bit clear exactly what it is I’m after. How about we start by listing interpretations? (My goal and the whole point of all this can be seen to later.)

Router A= TL-WR841N, and this one’s configured to connect to the internet using PPTP

Router B = Tenda W268R,

  1. I have two routers, and I want B to act as a wireless access point to extend it’s range.
  2. I have two routers, and I want B to have a LAN of it’s own, with A as a gateway providing access to the internet.
  3. I want to do either of the things listed above over a wireless bridge.

Let me say this much. I am a newbie. I’m not much of a networking guy, nor do I really know how this is going to work. I’m simply Google-ing and experimenting.

In the next few posts, I will explain what I have tried and what was the outcome.