Using doAsyncResult in Anko

I was stuck on this for a little while since it wasn’t updated in the documentation and also since I am still a newbie at Kotlin šŸ˜‰

Some of the description has been already added in the code, as you can see. Let me explain the premise of this solution in any case. The problem arose because I had to perform a network task in the onCreate method and as you know we can’t normally perform a network task in the uiThread. Luckily, Anko provides an elegant solution to this without having the need to implement an AsyncTask interface. doAsync runs whatever task you give it but does not return anything. However, although doAsyncResult is similar to doAsync it can additionally return an object.

A Merry Christmas to you!

Manga Review: Bleach

Before I begin describing Bleach, I should make it clear that Bleach is quite an underrated production (my guess is because of the anime which forked from the original story) since the Manga on the whole was pretty exciting. I can sense the reason for the hype for Bleach, but trust me… The hype would have been more if maybe the anime reproduction was a little better.

So what comes to mind when someone says Bleach? Detergent, eh? (Just kidding, even if you were thinking of it) Well, to a person like me who analyses anime (and stories as such) it didn’t feel as though the flagship victory of Bleach belonged to either Zanpaktous, or Bankais but instead the main glory of Bleach were its characters! (You probably think that I say this for every review, um yeah, you are sort of right). But it’s true. Really. I do mean what I say, that the most important point going for Bleach is really its characters.

Did you notice how new characters were introduced with the beginning of a sub arc (within an arc. To be quite fair here, Bleach can only be said to have 3 arcs). Hiyori, Risa, Keisei, Shinji and later Nel, Dondochakka, Pesche, etc. you realize that these characters played a huge role in those arcs and even got mixed up in on the action in subsequent arcs. It was quite masterful of Kubo to juggle the personalities of as many characters and choreograph some great conversation between them to build their roles in the story and build the story at the same time. Pretty cool, huh! Every single character who plays some part (even a small one) has been fleshed out pretty well if you ask me. And it is the conversation between them that are so lively and comical that it makes you feel as though Bleach is not just some Shounen-action dance, but a well nurtured baby of Kubo Tite.

Speaking of arcs, there are only 3 as I have mentioned before. First is the best in my opinion. Second is the shortest, but has the least amount of character development (a.k.a my satisfaction level), and the third is neither the longest nor the best out of the three, and it’s not the worst either… Better to be on one side rather than in the middle, anyway that doesn’t even make sense. But the first arc (Aizen arc, even the name of this arc is a spoiler darn it!) captures the true colours of what Bleach can offer you. Sucks right? The first is the best and you just have to read 250~ more chapters after it just to finish the manga. Don’t fret, it’s not bad as I make it sound. On the contrary, it is… wait for it… Boring! The last two arcs really lack what the first arc had in abundance, comic relief. Although, the amount of fighting that takes place in the final two arcs in 250~ chapters is almost about equal to the amount of fighting that takes place in the first 400~ chapters (first arc). Just imagine, you have to go through hours of text about two men provoking and taunting each other and talking about how great they are (and in the end both sides are beaten up pretty badly). So you know now what you are up against.

Well, look here now. On the bright-side I will make a prediction based on the fact that although I haven’t watched the anime and I have no details at all about where it forks away from the Manga that the manga is definitely better than its anime counterpart. Let me explain to you why this fact seems so apparent to me. Because of the ratings of Bleach on MAL. Wait a second. It seems like the manga has got an even worse rank than the anime (x3 times bad). I might be wrong here. But that shouldn’t be a problem, you can both watch and read it if you like and decide for yourself šŸ™‚

The only other problem that I noticed was the way the manga was the drawing of the fights was quite unintelligible. I mean honestly, I gave up trying to decipher what was going on in the picture. Like dude! If you are going to make a manga that’s mostly about fighting, at least make sure that you can draw the fights properly! Pah! That was the most annoying part. But I got used to it after a while. Also, it seemed as though the final arc ended a bit abruptly. I thought it would go on for at least 25 more chapters… Well, whatever, never mind.

As the conclusion, I would say that if you ain’t got time, read the first arc and then jump to the last chapter. If you think about it, the number of character additions keeps on reducing as the number of arcs increases. Members of Xucution in the 2nd arc (that’s around 6 I suppose) and the 5 members of the Zero division in the 3rd. In other words, Bleach loses what it had going for it in the first arc. Just look how many characters were introduced there (well of course it was the first arc, but even then. Characters being the charm of Bleach it would seem that it became a little rusty as the story went forward). Trust me, that might just as well be the best advice of the day given to you.

Switching over from http to https

Hip hip hurray! I recently made the switch using a popular and open source service known as Let’s Encrypt. Its service provides an SSL layer over the connection so that information sent to the server will not be understandable by the attacker even if they listen on the network. Well, to be honest I’ve been wanting to do this for a long time, but I did not know about this free service before! It works really well and a couple of tutorials helped me set up my Nginx WordPress installation for https.

So yeah, those lines above did it for me. But before you add them to your Nginx configuration file, follow the steps given on the Let’s Encrypt site. You need to start by installing certbot on your system, then create certificates and keys. Since these certificates expire after 90 days, you also need to renew them periodically. But rest assured, the setup was easier than I had expected, you should certainly give it a try. Not to mention that it’s free šŸ™‚

Haikyuu!! Season 2

This review had been pending for several months now, I watched Haikyuu!! S2 before my finals, and then my vacations had a lot of hustling, but now as I can sit on my swiveling computer chair and relax it might be a good time to pen down my thoughts on this anime.

Haikyuu!! is clearly a unique anime, because there’s no anime that’s as good as this! S1 was a smash-hit already, then the creators had to come up with the second season, which was a continuation of the first and when I thought S1 was as good as it gets, S2 surpassed my expectations! You might have guessed, it has become my favorite sports anime series.

So this time, I.G decided to spice things up by changing the mostly male demographic by addingĀ oneĀ more female. Hurrah for the improv. But in any case, not like there were hints of romance. OK, maybe yes. Wait, lemme think… What?! No! You call that romance!

So yeah, Haikyuu!! S2 mostly has romance in it, more than volleyball. Yachi-san becomes Hinata’s love of life, he quits volleyball, gets married to her, and THE END!

Watch the anime, if you haven’t yet šŸ˜‰

Creating a Bootable USB

Recently, I had the need to create a bootable USB to install the new LTS version of Ubuntu on my laptop. I stumbled upon a tool called Rufus which did the trick very well.

But there were several problems along the way, most because there weren’t clear instructions on all the sites that I visited in order to learn how to create a bootable USB.

The first thing that you have to do is download the tool, whichever OS you are on. Run it, and browse for the disk image. Select the GPT partition style in the dropdown menu, and now the most important part:

Set Create bootable disk using to DD tools!

I was stuck here because I was using ISO image instead. When I tried booting my USB on startup I got a “Missing operating system” message. I got the same message even when I created the bootable USB using the tool provided by Ubuntu!

How the LinkedList class in Java works

I will explain how to perform operations like add, push, pop, poll, etc on LinkedList and what they mean. At first, it may seem a bit confusing, but I hope this article resolves a few conflicts.

A simple LinkedList of Strings declaration and definition looks like this:

There are several ways to add new elements to a LinkedList, but they mean and do different things. I will show you how each function works one by one.

add

One of the first methods you might encounter to add an element to a LinkedList is add. You can make use of add function in this manner:

Now let’s try to do the same with push!

push

We can conclude from this that add puts the element at the first position and then moves on to further positions. push on the other hand inserts elements quite like a stack. The element that is inserted first is the last when we traverse the linked list.

Let’s look at ways to fetch elements from the LinkedList. For this, we need to assume that the linked list already has some elements. Assume that for the subsequent examples, the LinkedList contains elements added using the add method like above.

pop

Just a reminder that elements are added in the same fashion as in add.

Since pop and poll are nearly the same (poll returns null when the list is empty whereas pop throws an exception) I will not discuss poll.

pollFirst

Just a reminder that elements are added in the same fashion as in add.

As can be seen, pollFirst and pop function produce similar output.

pollLast

Just a reminder that elements are added in the same fashion as in add.

And finally, pollLast!

Why people play MOBA

Usually, a lot of things in life are based on actions and consequences. When you act on something you can somewhat (if not fully) expect what the consequences will be. This theory has way too many variables in games like LoL where prediction on whether you will be the victor or loser depends on a multitude of configurations, players, their states of mind, their alertness, knowledge of the game, reflexes just to name a few. Non-scientifically you could even say these games are equivalent to gambling! That’s how unpredictable they are.

Victory depends not only on you but also on how your team plays, but at the same time without you your team will lose. It depends on the enemy team as well, and each and every player contributes to their team’s fate.

“Mayhaps this is a game of luck, like battleship”, you might say, but think about the hours of practice and the experience people have gained in order to control the turn of events in the game! It’s like reliving a war every time. There’s a Japanese saying which goes like, “A war is won before it is fought”. Mayhaps wars are inevitable, and mayhaps people are forced to join it even if it’s against their will. Mayhaps even the above quote is more intuitive than it seems.

But we don’t know unless we play :3

The confusing yet awesome behaviour of the DatagramSocket class

One of the recent projects that I am doing involves using UDP datagrams for communication. The DatagramSocket class in Java enables me to use that feature. At first, I wasn’t aware of all the features of the class, but as I started coding and explored different methods of using that package, several more things became clear to me. Well, firstly the documentation and tutorials that I looked up to understand how to use the class gave me a very minimalistic approach to using it. So, let me clarify how this class manages the network and how you can use this.

Let’s start with the constructor. For a minimalist working server, you must provide a port (otherwise packets might not get delivered to you). Basically, the DatagramSocket class takes care of listening to a port and sending data from that same port (if needed). It does not automatically send ACKs when a packet arrives. It listens, halts the process till data arrives.

A client on the other hand does not require a port to be specified in the constructor for minimalist working. Why? Because we are assuming that the client is not listening for any data (for the time being). It only sends the provided data to a specific port specified by an InetAddress. Now there is an important thing to understand about all this. If a port is not specified by the client, it randomly chooses one. Not specifying a port does not mean that a port is not required by the client to send the data! When the DatagramPacket arrives at the server’s end, the server can find out from the packet several things like the InetAddress of the source and the port through which the packet was sent. This allows the server to send data to that source through it’s address and on the port that it’s using.

The conclusion that can be drawn from these facts is pretty cool. A thread that’s listening on a port can receive packets from multiple sources, and in the same way a thread that’s sending packets can send them to different hosts!

UPDATE:
The real important thing to remember is that you cannot use the same socket simultaneously for sending and listening. If a socket is listening on a certain port, you need to either make it stop listening and send your packet away or you need to open another socket to do so.

Of course, it is not possible to listen on multiple threads using just one socket. For this reason, one of a good architecture designing techniques for such a mechanism is as follows:

  • Listen on one socket
  • Send packets using another socket

Summing up MOBA

Recently, I made the big decision of quitting my temporarily largest addiction: MOBA games. I had to one time or the other, for fear of becoming a gaming couch potato. But I am thankful for making that spontaneous decision which brought more good than I expected.

But since MOBA was something that I gave a LOT of my time to and dedicated hours of thinking and understanding to, I decided to sum up my experiences while stuck in its delirium. For those who are not aware, MOBA stands for Multiplayer Online Battle Arena. I had been posting my views about two major games in this category forĀ the last couple of months.

The reason this genre is so addictive is because of its unpredictability and the numerous combinations of heroes/champions and items that can be played with and bought in the games. If you’ve read my previous articles, you know that I am talking about Dota 2 and LoL. People still play even though there is hardly any choice of maps. That alone tells us how insanely addictive it can be.

The most important thing that you must focus on in the game can differ from game to game, or character to character or even position to position. It is complex, and not only depends on a player’s expertise in hand-eye coordination but also on their team picks and even the opponent’s team picks. The possibilities do not end there. As the game progresses, players accumulate gold which can be used to buy items. Those items have abilities as well.

Despite all that clutter and complexity, one thing is clear, your character should aim to level up as fast as possible. Items can offer bonus stats, but the real boost comes from levelling up. Which is why in pro tournaments, we don’t find players picking up all the attack damage and powerful items whenever they have enough money. Rather they communicate with their team and decide strategically which item must they pick.

It is a team game of course, which means that the responsibility of both winning and losing are partly on everyone’s shoulders. But that also means that if one out of the five players is not playing well, the match may well be in jeopardy. It happens all the time.

To conclude, the only logical thing that I can say confidently is that there is no way to predict if your next match will be a victory or defeat. You just can’t say. It’s a pity but that’s what makes it all the more exciting, right?

First game as Spectre

One day before my mid semester examination.

Well, it wasn’t my first game to be completely honest here, because on my actual first time my PC crashed and by the time I had reconnected I got an abandon. I cannot blame Steam for this. JustĀ this new modem (I have no clue what the hell is wrong with it). So, I played a Single Draft match with Axe (my first time) and we won! What luck that is huh. Axe has a pretty lousy ult btw. It doesn’t do any real damage from what I saw [update: now I know how to play him]. The only good thing about him is that he’s kinda tanky like all the male characters in dota (and also that he can deal more damage when he’s alone). So anyway, we won that match somehow (I forgot to mention we had a broodmother whose user was at level 52! Yeah, after that match I decided that I had to play Spectre again because I didn’t get to test her out fully the last time (if you count that).

This time the enemy team her strong picks like Juggernaut (god knows why he’s picked inĀ every match), Sven (goddamit this guy!), Huskar (Mista Gank), Naga (she was total noob and fed like anything), and somebody else (I forgot). We had myself (Spectre), Templar Assassin (girls get to have all the fun), Phantom Assassin (the girl who I first thought was a guy), Venomancer (amiable support) and of course Sniper (apparently the character everyone hates). I assisted in getting first blood I think. Spectre does good damage with her Q initially. Out team had less conventional picks unless you want to include PA with her ‘blur’ evasiveness.

In any case, I took the bottom lane with Venomancer and he was a really helpful support. I remembered the last hero of the enemy team: Spirit Breaker (damnĀ those stuns!). The thing was that most of the time the whole (at least 3-4) heroes of the enemy team would suddenly appear and gank. Lots of times Sven killed me. I fed quite a bit in the beginning and hoped that the rest of my team was doing well in absence of the enemy heroes in their respectiveĀ lanes. Funnily enough it played out quite exactly like that. The got plenty of farm and one tier-3 tower of top lane also fell. I believe PA was top. Either her or sniper. Once I got my ult, I could teleport to any team fight that I chose and we started winning team fights. Not only because of me, PA, TA were playing great too. But I got the highest number of kill assists: 29. I thought this match would be cutting it close, but I was wrong. We won pretty easily. I usually feed a lot in the beginning. But as the game progresses I start getting kills and assisting. I got a battle fury first, then Radiance and finally a moon shard which I consumed and then bought another one. What do you basically need? Good damage and attack speed! That’s something I learnt playing LoL. Speaking of LoL, it’s mechanics are totally different compared to Dota. Which is better I cannot say, but LoL looks to beĀ the one attracting the crowds.