Thursday, March 29, 2018

Table topics side project upfront design

Prior to starting, I wondered why not have some sort of design up-front. This will also help avoid going out of scope and strive to establish a baseline to move forward from.

This webapp will have all the data in sqlite probably. The index page will have some general information. Listed here are some key pages we will incorporate.

Tags page: This will show all the relevant tags out there. Once clicked on the required tag another page with all. A wireframe later on could be hatched out similar to below main page wireframe. This can be left as an exercise for free time.

Main page: Display all with pagination. If there are 100 topics display 10 topics per page. So this is accommodated in 10 pages overall. The index page wireframe is sketched out: https://wireframe.cc/GMUaUB



Optional: Search box leveraging search utility such as Whoosh. There exists extensions for Flask that could fill this gap. This could be displayed in all pages and hence in the parent template.

With the extent of functional aspect out of view, let us focus on the relationship of data when a post belongs to one or more tags. This calls for a many-to-many relationship.


To be continued...


Wednesday, March 28, 2018

Project ideas

This would act as a placeholder and a brain dump ;)

  • Reddit bot to respond when a post has all caps

Quote of the Day


I wanted to work on a side project over the weekend. That would involve creating a website that generates table topics.

This is a small project in Flask framework. What I essentially did was to hit a Quote Generator API. The request library in Python helps do that and even do the germane JSON transformation and response building.

Just wanted to get the ball rolling. Although from cosmetic perspective could throw in some CSS as well but what the heck!

This has me all set in the right direction. Some key things to get right next time:


  • Download bootstrap instead of CDN
  • Create a separate css folder in static
  • Add virtualenv and relevant file formats to .gitignore

Tuesday, March 27, 2018

Triaging tries [Draft]

I was reading through How to Solve it by Computer however, couldn’t find anything on trie. A mechanism to search for and insert strings. Following from other search tree data structures we will build a search tree. I've taken Sedgewick's algorithm book for reference.

Basic properties
Root does not have any character key as well as value in it unlike other nodes that have characters associated with it.

We will describe the technique by which an R-way trie operates. The string for example we have “she sells sea shells by the sea shore”. The last character of the key has a value associated with the node. This is usually the index of the key within the original string. For instance, the key she will have the value as “0” on the last node having the last key character, in this case “e”.

Searching
For searching, we follow all the characters in the key and return the value corresponding to it in order to indicate the search succeeded otherwise a null value at the end indicates that the key does not exist within the trie. With this out of the way let’s see how code would look like:

Insertion
To insert any key we first and foremost search within the trie. If it doesn’t exist we create a new start node and move ahead similarly.

Deletion
Deletion works by traversing to the value of the last key character and if at all found remove that node. And go backwards and delete nodes until you find a node that has a corresponding value.

Other key operations among others
keysWithPrefix – This will return a queue with similar keys that matches the input key

Advantages
Use trie when search should include prefixes otherwise a hash table would suffice.

Friday, March 23, 2018

My experience with Carpooling

In the past couple of months I was sort of compelled to try out carpooling to my office. I've been on both sides of the table(either as a ride giver or a ride taker) and I'd say I've had mix experience. At the end of the day I don't regret doing that.

A friend had introduced me to Quick Ride Android app. The app was reliable at least during the  early stages. It was no hassle getting rides in the morning though it was a challenge while leaving work. Even SRide app connected me to trustworthy carpoolers.

Some days passed by, I was made a part of a WA group and yeah this made me acquainted with some nice folks. However, when giving rides I noticed some idiosyncracies:

  • Fellow riders asking intrusive questions like how much the car costed and grilling why I preferred one brand over another if my mileage is less
  • Questioning how much I make blatantly
  • Whether I stay in a rented or owned house

That too when you are meeting someone for the first time. Another incident that is fresh is one guy was arguing left and right during the whole time. It was the tipping point where I decided upon to only carpool with a select few. 

Overall it was a decent experience with the only caveat avoid carpooling with total strangers.

/ Rant end


Starting off with Angular Observable

Angular 4 allows sending async/sync request with one more concept called Observable apart from Promises. This is leveraged via RxJS library. Observables are based on Observer design pattern. Let’s take a quick detour prior to delving into Observables what the Observer design pattern is all about.

Think about it this way. Let’s say you are subscribing to any TV channel of interest. In this case you are Observer (among a list of subscribers) and the channel is a point of interest (technically called as Subject or Observable). The Subject maintains logic to register an Observer. The Subject notifies the observers through a call to their internal logic. This creates a separation of concerns. Regardless, I digress. This is a story (read blog post) for another time.

Moving on to Observable in Angular. Let’s suppose the backend is sending across Movie details. This will be a REST call in the form of sending back a JSON.

In our service class we will hit the Spring backend and ask for a response for a list of those movies persisted on the server. The http.get constructs an Observables that the MovieList Component can subscribe to. Following is the relevant piece of code:

getMovies (): Observable<Movie> {
    return this.http.get<Movie>(this.movieUrl);
}

Now in our component, we call the above method in the service. This being an observable we subscribe to it. We use something along the lines of:



getMovies(): void {
    this.movieService.getMovies()
        .subscribe(movies => this.movies = movies,
           error => console.log("Error :: " + error))
}

The above console statement was just for the sake of it as this is a contrived example.

And this can be in turn iterated over in our template by means of ngFor. This I believe has just scratched the surface. Later on I will cover the different operators on the Observables.

Thursday, March 22, 2018

First look at Java 9

The introduction of Java 8 was quite groundbreaking in that the rollout of the new lambda syntax. The whole "functional" approach created quite a buzz.

I was just casually browsing my LinkedIn feed and came across the Java 9 article. Skimming through that as well as the official Oracle blog here are the key things that were added:


  • Factory methods to initialize collections. Earlier the idiom to initialize it were quite verbose. The following is how to declare it:
  • List<String> list = 
        List.of("Ahsan", "Tom", "Jerry");
    
  • The Optional class that was introduced in Java 8 to deal with Null pointer exception has gone some makeover
  • The Stream interface that works with a collection has been enhanced. More on this in the later blog post

Friday, March 16, 2018

Microservices is just enhanced SOA

Like dependency injection, Microservices is yet another instance where buzzwords and jargons take precedence over simplicity.

Microservices claims that it is independently deployable as a distinguishable feature. What is stopping SOA instances from being deployed separately.

Stack Overflow had a question along the same lines. It also confirmed my opinion that microservice is a redundant name.

Instead call it independantly deployable SOA.