Monday, 10 February 2020

Web Tutorial: Tic-tac-toe, Valentine's Day Edition (Part 1/2)

Can you feel the romance in the air?! Valentine's Day is coming up, lovebirds, and boy do I have the web tutorial for you today.

Remember last year when we made this neat little Tic-tac-toe game in HTML, CSS and JavaScript? Today, we will revisit it and improve on it. We'll first put a little Valentine's Day theme to it, and then we'll even implement some artificial intelligence. All while leveraging on the existing code.

First, the colors!

It wouldn't be Valentine's Day if we didn't saturate this sucker with unhealthy doses of red and pink, so let's make some changes to the CSS. That's right... turn the buttons red, and pink on a mouseover.
.btn
{
    font-family: "Comic Sans MS";
    font-size: 2em;
    display: block;
    width: 5em;
    height: 1.5em;
    border-radius: 0.5em;
    border: 0px solid;
    background-color: #FF0000;
    color: #FFFFFF;
    margin: 1em auto 0 auto;
}

.btn:hover
{
    background-color: #FF8888;
    color: #FF0000;
}

A good beginning...

The board needs a little makeover as well. Lighter shades of pink should do it.
#board_container
{
    width: 330px;
    height: 330px;
    margin: 0 auto 0 auto;
    background-color: #FFCCCC;
    padding-top: 10px;
    padding-left: 10px;
}

.square
{
    width: 100px;
    height: 100px;
    margin-right: 10px;
    margin-bottom: 10px;
    float: left;
    outline: 1px solid #FFEEEE;
    background-color: #FFFFFF;
    cursor: pointer;
}


And for good measure, we'll even change the colors of the users.
#user_x_container
{
    color: #FF0000;
}

#user_o_container
{
    color: #FF8888;
}


Ooh, sappy, eh?


Now, for the tokens, instead of "X" and "O", we'll use hearts of a different color.
{
    content: "\2764";
    color: #FF0000;
}

.o:before
{
    content: "\2764";
    color: #FF8888;
}


And upon winning, this shade of pink should contrast nicely with both colors!
.win
{
    background-color: #FF4444;
}


Here you go.


Oh hey, here's a cheeky touch.
<h1>Let's play Tic-tac-t&hearts;e!</h1>


Damn, so cheesy.


Some randomly fun features

I think it's a wee bit boring to have the facial expressions unchanged, and the messages look repetitive. So let's introduce a random element into all this.

Add the getRandomRemark() method into the game object.
var game =
{
    turn: "x",
    started: true,
    board:
    [
        {square: "a", value: ""},
        {square: "b", value: ""},
        {square: "c", value: ""},
        {square: "d", value: ""},
        {square: "e", value: ""},
        {square: "f", value: ""},
        {square: "g", value: ""},
        {square: "h", value: ""},
        {square: "i", value: ""}
    ],
    winPatterns:
    [
        [
            {square: "a", value: ""},
            {square: "b", value: ""},
            {square: "c", value: ""}
        ],
        [
            {square: "a", value: ""},
            {square: "d", value: ""},
            {square: "g", value: ""}
        ],
        [
            {square: "a", value: ""},
            {square: "e", value: ""},
            {square: "i", value: ""}
        ],
        [
            {square: "b", value: ""},
            {square: "e", value: ""},
            {square: "h", value: ""}
        ],
        [
            {square: "c", value: ""},
            {square: "f", value: ""},
            {square: "i", value: ""}
        ],
        [
            {square: "c", value: ""},
            {square: "e", value: ""},
            {square: "g", value: ""}
        ],
        [
            {square: "d", value: ""},
            {square: "e", value: ""},
            {square: "f", value: ""}
        ],
        [
            {square: "g", value: ""},
            {square: "h", value: ""},
            {square: "i", value: ""}
        ]
    ],
    init: function()
    {
        this.started = true;
        this.turn = "x";

        for (var i = 0; i < this.board.length; i++)
        {
            this.board[i].value = "";
        }

        for (var i = 0; i < this.winPatterns.length; i++)
        {
            for (var j = 0; j < this.winPatterns[i].length; j++)
            {
                this.winPatterns[i][j].value = "";
            }
        }

        for (var i = 0; i < 9; i++)
        {
            document.getElementById("square" + i).className = "square";
        }

        var texts = document.getElementsByClassName("text");
        for (var i = 0; i < texts.length; i++)
        {
            texts.innerHTML = "";
        }
    },
    play: function()
    {
        document.getElementById("btnPlay").style.display = "none";
        document.getElementById("btnQuit").style.display = "block";
        document.getElementById("game_container").style.display = "block";
        this.nextTurn();
    },
    quit: function()
    {
        this.init();
        document.getElementById("btnQuit").style.display = "none";
        document.getElementById("btnPlay").style.display = "block";
        document.getElementById("game_container").style.display = "none";
    },
    getRandomNumber: function(min, max)
    {
        return Math.floor((Math.random() * (min - max + 1)) + max);
    },
    getRandomBlankSquare: function()
    {
        var blanks = this.board.filter(function (x) {return x.value == ""});

        if (blanks.length == 0)
        {
            return null;
        }
        else
        {
            var rand = this.getRandomNumber(0, blanks.length - 1);
            return this.board.findIndex(function (x) {return x.square == blanks[rand].square});   
        }
    },
    nextTurn: function()
    {
        this.turn =  (this.turn == "x" ? "o" : "x");
        user.myTurn();
    },
    checkWin: function(mark)
    {
        var findSquare;

        for (var i = 0; i < this.winPatterns.length; i++)
        {
            if (this.winPatterns[i][0].value == mark && this.winPatterns[i][1].value == mark && this.winPatterns[i][2].value == mark)
            {
                for (var j = 0; j < 3; j++)
                {
                    var winPatterns = this.winPatterns;
                    findSquare = this.board.findIndex(function (x) {return x.square == winPatterns[i][j].square});
                    document.getElementById("square" + findSquare).className += " win";                           
                }

                return true;
            }   
        }

        return false;
    },
    getRandomRemark: function()
    {
   
    }               
}


Define a variable, remarks. It will be an array of objects.
getRandomRemark: function()
{
    var remarks =
    [

    ];
}   


Each object has the properties face and text. face is the HTML symbol used to accompany the remark, and text is the remark itself.
getRandomRemark: function()
{
    var remarks =
    [
        {face: "&#9786;", text: "Looks like it's my turn!"},
        {face: "&#9854;", text: "Brilliant move!"},
        {face: "&#9785;", text: "Ouch!"},
        {face: "&#9863;", text: "Um..."},
        {face: "&#9863;", text: "This is hard."},
        {face: "&#9786;", text: "Let me see..."},
        {face: "&#9786;", text: "I'm gonna cream you!"},
        {face: "&#9786;", text: "Ooh. Nice."}
    ];
}


Grab a random number using the existing getRandomNo() method, passing in 0 and the length of remarks minus 1, as arguments, and assign the value to the variable rand.
getRandomRemark: function()
{
    var remarks =
    [
        {face: "&#9786;", text: "Looks like it's my turn!"},
        {face: "&#9854;", text: "Brilliant move!"},
        {face: "&#9785;", text: "Ouch!"},
        {face: "&#9863;", text: "Um..."},
        {face: "&#9863;", text: "This is hard."},
        {face: "&#9786;", text: "Let me see..."},
        {face: "&#9786;", text: "I'm gonna cream you!"},
        {face: "&#9786;", text: "Ooh. Nice."}
    ];

    var rand = this.getRandomNumber(0, remarks.length - 1);
}


Finally, return the array element pointed to by rand.
getRandomRemark: function()
{
    var remarks =
    [
        {face: "&#9786;", text: "Looks like it's my turn!"},
        {face: "&#9854;", text: "Brilliant move!"},
        {face: "&#9785;", text: "Ouch!"},
        {face: "&#9863;", text: "Um..."},
        {face: "&#9863;", text: "This is hard."},
        {face: "&#9786;", text: "Let me see..."},
        {face: "&#9786;", text: "I'm gonna cream you!"},
        {face: "&#9786;", text: "Ooh. Nice."}
    ];

    var rand = this.getRandomNumber(0, remarks.length - 1);
    return remarks[rand];   
}


In the myTurn() method of the user object, remove this line.
myTurn: function()
{
    document.getElementById("user_x_text").innerHTML = "";
    document.getElementById("user_o_text").innerHTML = "";
    //document.getElementById("user_" + game.turn + "_text").innerHTML = "My turn!";


Instead, declare the variable remark and set it to the object returned by calling the getRandomRemark() method of the game object.
myTurn: function()
{
    document.getElementById("user_x_text").innerHTML = "";
    document.getElementById("user_o_text").innerHTML = "";
    //document.getElementById("user_" + game.turn + "_text").innerHTML = "My turn!";

    var remark = game.getRandomRemark();


Then use the face and text properties to populate these placeholders.
myTurn: function()
{
    document.getElementById("user_x_text").innerHTML = "";
    document.getElementById("user_o_text").innerHTML = "";
    //document.getElementById("user_" + game.turn + "_text").innerHTML = "My turn!";

    var remark = game.getRandomRemark();
    document.getElementById("user_" + game.turn + "_text").innerHTML = remark.text;
    document.getElementById("user_" + game.turn + "_face").innerHTML = remark.face;


Also, in your HTML, add ids for these placeholders.
<div id="game_container">
    <div id="user_x_container" class="player">
        <div class="token" id="user_x_face">&#9786;</div>
        <div id="user_x_text" class="text"></div>
    </div>

    <div id="board_container">
        <div id="square0" class="square" onclick="user.takeTurn(0, 'o');"></div>
        <div id="square1" class="square" onclick="user.takeTurn(1, 'o');"></div>
        <div id="square2" class="square" onclick="user.takeTurn(2, 'o');"></div>
        <div id="square3" class="square" onclick="user.takeTurn(3, 'o');"></div>
        <div id="square4" class="square" onclick="user.takeTurn(4, 'o');"></div>
        <div id="square5" class="square" onclick="user.takeTurn(5, 'o');"></div>
        <div id="square6" class="square" onclick="user.takeTurn(6, 'o');"></div>
        <div id="square7" class="square" onclick="user.takeTurn(7, 'o');"></div>
        <div id="square8" class="square" onclick="user.takeTurn(8, 'o');"></div>
    </div>

    <div id="user_o_container" class="player">
        <div class="token" id="user_o_face">&#9786;</div>
        <div id="user_o_text" class="text"></div>
    </div>
</div>


Before I forget, also populate the "face" placeholder when the game is won.
if (game.checkWin(mark))
{
    document.getElementById("user_" + mark + "_face").innerHTML = "&#9786";
    document.getElementById("user_" + mark + "_text").innerHTML = "I win!";
    game.started = false;
}
else
{
    game.nextTurn();
}


Oh, ho! Now things are getting interesting!



Next

Let's simulate some intelligence in this game!

Thursday, 6 February 2020

Spot The Bug: The Calendar Conundrum

Hello and welcome! It's time for another episode of Spot The Bug!

I know you're
out there.

Ruby is a nice language to use with a syntax that is smooth as silk, but surprise, surprise... you can get code bugs in Ruby just as easily as any other language.

Here's what happened when I tried to use Ruby to write a script that would display a calendar view for the current month. For the record, it was this month of this year - February 2020.

In here, calStr is a list of dates, each one separated by a tab, and a break every time Saturday is encountered.
require "date"

nowDate = Date.today
currentDate = Date.new(nowDate.year, nowDate.month, 1)
lastDate = currentDate >> 1
lastDate = (lastDate - 1)
lastDay = lastDate.day

puts "Sun\tMon\tTue\tWed\tThu\tFri\tSat"
calStr = "";

for i in 1..lastDay do
    currentDate = Date.new(2020, 2, i)

    calStr = calStr + i.to_s + "\t"

    if (currentDate.wday == 6)
        calStr = calStr + "\n"
    end
end

puts calStr


Not too bad, right? Except the first day doesn't start on a Sunday, so the calendar is all wrong.


No problem! What I'll do is make another For loop before the For loop, to iterate from 0 to the first day. Then I'll print a tab character for every day before the first day!
puts "Sun\tMon\tTue\tWed\tThu\tFri\tSat"
calStr = "";

for i in 0..currentDate.wday do
    calStr = calStr + "\t"
end

for i in 1..lastDay do
    currentDate = Date.new(2020, 2, i)

    calStr = calStr + i.to_s + "\t"

    if (currentDate.wday == 6)
        calStr = calStr + "\n"
    end
end

What went wrong

Um... nope. For some reason, now the first day, 1, was out of alignment. But everything else was in alignment.


This only meant one thing - the number of tabs before the first date, was wrong. There was an extra tab.

Why it went wrong

See, one of the nice things about Ruby is that it utilizes ranges. Instead of painstakingly typing out stuff like for (int i = 0; i < x; i++), you can simply go for i in 1..x do. 1..x is the range and you can do a lot more with that. Follow this link for more about Ruby ranges!

Anyway, where I went wrong was the range. Ruby range syntax goes like this...

If you want to go from 0 to 10, you use this.
0..10


If you want to go from 0 to 9, excluding 10, you use this. See the extra dot?
0...10


I only had two dots in my range 0..currentDate.wday. Therefore the script would churn out a tab character from 0 to the first weekday... including the first weekday! So even if the first weekday was on a Sunday, there would still be a tab in front of it!

How I fixed it

That's right, all it took was an extra dot. Which meant only the number of tabs from 0 (Sunday) to the first weekday of the month (Saturday), five in all, would be printed.
for i in 0...currentDate.wday do
    calStr = calStr + "\t"
end


Voila!


Moral of the story

It's usually the very tiny things that elude us. And in this case, it was literally a dot.

Till next time..............................
T___T

Sunday, 2 February 2020

Four Hundred Dollars Below Budget

My monthly budgeting follows a strict routine. Every month, my company pays me by transferring funds into Account A. Every month on the 25th, I transfer a thousand dollars into Account B from Account A, and all my personal spending draws from Account B. Now, I don't spend exactly a thousand a month, but it's close enough. Any amount I put in or withdraw from any of my accounts sends a message to my phone.

Yes, I'm a control freak like that. There was a time when I lived from paycheck to paycheck, and it's resulted in certain habits.

So imagine my consternation when recently, before performing my monthly funds transfer into Account B, I looked into Account B and found that there was an extra four hundred dollars just sitting there. Four hundred. Not forty. Where had it come from? None of my notifications showed an incoming transaction by that amount. Was there a bill I'd forgotten to pay? Had the Singapore Government inserted money into my account (some National Budget or other, maybe?) and somehow forgotten to tell me?

I'm rich!!!

People told me I was fretting over nothing. Extra money in your account is a good thing, they said. Better than less money. Just relax and enjoy it.

Utter rubbish. That's the simplistic mentality of laypeople who don't write code for a living.

You see, people tend to focus on the end result, but the process is just as important, if not more. If there is a desirable result and you want to replicate it, it stands to reason that you have to repeat the process under the same conditions. If you don't even know what process should be repeated or the conditions to repeat it under, how are you to replicate that result?

An Example In Code

Here's an example in JavaScript. Say I have two functions, a() and b(). They each accept a parameter, x. Now let me run the function a() using 2 as an argument.

a(2);


Now, if a()'s formula was this...
a(2);

function a(x)
{
    return x * 2;
}


The result would be 4. Because 2 x 2 is 4, right?
4


But what if the formula for b() was this? And then we ran b() using 2 as an argument?
b(2);

function a(x)
{
    return x * 2;
}

function b(x)
{
    return x * x;
}


The result would be the same. Because x is 2, thus it would still be (2 x 2 = 4)!
4


That's a very simple example of how an identical result does not equate to an identical formula. Obviously, x multiplied by itself is not the same formula as x multiplied by 2, unless x is 2. What if x wasn't 2? What if x was some other value, say, 10? Then the two formulae would yield very different results.

The Takeaway

Thus, when testing code, you test with a variety of input and in a variety of environments, to ensure that the formula is correct. Because if you get what appears to be the correct result while applying an incorrect formula, your code is still incorrect. And this will lead to further problems down the road.

Apply the correct formula.


As a professional who codes for a living, I've had to sometimes apply certain code-related principles to life. If you want to ensure that your results are favorable, you have to apply the correct process with the correct input. It was never an issue of whether there was more or less money in my account. People were missing the point by a mile. The issue was that I didn't know where that money came from. That made me uncomfortable. It was imperative that I understand why there was extra money in my account.

Finally...

So where did that money come from? The answer was a lot simpler than I'd imagined.

During those few months, I was so busy with work that I didn't have time to go out and spend money. No fancy dinners, no movies, no whatever. And I was certainly too busy to check and see how much money there was in Account B before the monthly funds transfer. Thus whatever money that was left over at the end of the month, just kept accumulating.

And when I finally found the time to look, the sum had grown to four hundred dollars. Since it wasn't a result of anybody transferring money to my account, I naturally never received any notification.

Looks like I'm not as savvy as I thought, eh?

Warm regard$,
T___T

Thursday, 30 January 2020

Wuhan Coronavirus: A techie's random thoughts

The outbreak has arrived. It's been a week of worldwide panic as the 2019-nCoV, otherwise known as the Wuhan Coronavirus, started infectng the city-dwellers of Wuhan in the province of Hubei, China. Cases of infection soon hit Singapore and the rest of the world as Wuhan went into lockdown mode.

Contagion.

And this is of interest to me, why?

Well, firstly, here's the personal part. A few months ago, my Chinese national wife returned to her hometown of Zunyi in the province of Guizhou to celebrate the Lunar New Year with her family. Shortly after the outbreak in Wuhan began, there were three reported cases of infection in Guizhou. And as such, it's my matrimonial duty to stay on top of things. Underneath it all is the nagging fear that if things go really south, I could become a bereft husband instead of merely an anxious one.

Yes, this is how I manage anxiety - by blogging. Eat me.

Secondly, as a Singaporean, I have a vested interest in not having the Wuhan Coronavirus take root here. Although it may be a little late for that. As of today, the count of infected cases in Singapore has risen to ten, though thankfully there have been no deaths so far. More on that later...

And lastly, response to this outbreak has produced some truly neat stuff. I'd like to point to this real-time updated website by thebaselab.co which is a great example of a mobile-friendly API-data driven site.

Screenshot.


A cursory look at their source tells me it was quickly hammered out with Twitter Bootstrap and Google APIs. Impressive work. I might have slipped them a few bucks as a token of appreciation for their trouble, and if you found the information useful, you might want to do the same.

How Singaporeans have handled the situation so far

I've seen people step up in recent weeks.

Some have expressed concern for their fellow citizens and distributed supplies such as hand sanitizer and personal thermometers.

Singaporeans stepping up.


An ex-classmate of mine went the extra mile to source for surgical masks so that retailers would be limited in their ability to profiteer off this emergency. At this point, I'm not even sure the masks will be enough to prevent the spread, but come on, that effort has got to be worth something.

Some have done their part to combat the flood of fake news, conspiracy theories and stirred hysteria online, analyzing this outbreak in relation to previous ones such as SARS and MERS. The numbers, so far, have been somewhat reassuring.

Other Singaporeans... not so much.

There's been a petition going round to refuse entry to all Chinese nationals and travelers from China. The latter I could understand (even though that would not be in my personal interests, because obviously if my wife returned, she would be returning from China), but all Chinese nationals? Not all people with a Chinese passport have been to China in the past year. Some stay abroad for, y'know, work and shit. What, all Chinese nationals are suspect by virtue of simply being Chinese nationals? You know this looks suspiciously xenophobic, right? We're all understandably fearful for our families and all, but let's not get stupid.

This is what the SQL statement would look like. Imagine if tblArrivals was a relational table of all incoming people to our airport.

SELECT * FROM tblArrivals WHERE Nationality = 'PRC' and CountryOfOrigin = 'CH'

Number of records returned from that query? Definitely more than 1.4 billion. Because we would be including non-China citizens who just happened to be flying in from China.

Also, petitions don't work in Singapore. Period. A million of us could sign a petition and you would still have a better chance of winning the lottery twice in a row, than of pressuring the Singapore Government to do what we want. The Singapore Government will do what it deems fit, when it deems fit, which is pretty much their job in the first place. And honestly, if we knew better, we would be in governance.

Simply stopping incoming flights from Wuhan wouldn't accomplish anything. There are no incoming flights from Wuhan. As mentioned earlier, the city, indeed most of Hubei, is in lockdown.

What the Singapore Government has done, is stop entry or transit for new visitors who have traveled to Hubei in the last 14 days, as well as holders of Chinese passports issued in Hubei. This is a far more measured and reasonable approach.

This SQL query would look like this. In addition to the tblArrivals table, let's have a tblTravelHistory table.
SELECT * FROM tblArrivals WHERE PassportPlaceOfIssue = 'Hubei' AND ArrivalId IN
(
    SELECT TravellerId FROM tblTravelHistory WHERE Area = 'Hubei' AND Country = 'PRC' AND DateDeparted BETWEEN DATEADD(d, -14, GETDATE()) AND GETDATE()
)

That's a far smaller number than an absolute blanket ban on all Chinese nationals. Because if you really only want to prevent possible carriers from entering Singapore, remember that it's not actually their nationality that matters, but where they've been recently. A British visitor could be transiting from Malaysia, for example, having flown in from Hubei. A Chinese national could have been working in Malaysia for the past year and is now attempting to visit his cousin in Singapore. Who's the bigger risk?

Sorry, I'm rambling...

Did I mention that I'm anxious? God yes, I really fucking am.

The wife assures me that she's feeling fine. The streets are quiet and most of the city are staying indoors. The supermarkets are still open, though there's not much variety at the moment. I'm not a superstitious man by nature, but fingers crossed!

To your health,
T___T

Saturday, 25 January 2020

Film Review: Silicon Valley Season 5

Time for more Silicon Valley, and this Season ranks up there as one of my favorites. Possibly because there's so much less padding and we finally see Pied Piper in a place of some progress after watching them struggle for the past four Seasons.



This is the first Season where TJ Miller isn't around to play Erlich Bachmann, and to be honest I was expecting the vibe to change considerably. Well, it did, but the Season is not significantly worse off for it.

Warning

It's crude, it's rude, it's Silicon Valley! But to be honest, without Erlich around, the uncouthness factor has gone down a whole lot. It's still pretty fucking profane, though.

The Premise

After the events of last Season where they avoided a major legal and moral crisis, Pied Piper is making a little headway as they move into a new office and continue their partnership with Raviga. But Gavin Belson is back, and looking to sabotage their efforts by any means necessary.

The Characters

Thomas Middleditch plays Richard Hendricks, CEO of Pied Piper. There's a quintessential Richard scene where he admits that he's no orator, then proceeds to inspire by example instead, i.e, coding himself into a coma. Richard's far from perfect though. While he seems to have overcome his moral myopia from last Season, he still has a bit of a mean streak. The last episode of the Season features him, at different points, doing a mocking jerky dance while chanting "kiss my piss"! It's awkward in a way only Middleditch seems to be able to pull off. Having seen Middleditch make a cameo appearance in Zombieland: Double Tap recently, more of that earnest geeky awkwardness is on display here.

Zach Woods as Jared Dunn. As in last Season, he's the conscience of the team and this comes into play in the first few episodes where he handles an impending lawsuit like a pro, acting with a lot more maturity and humility than we've seen from the rest of the team combined. The moment where Richard promotes him to COO is a huge heartwarming moment. Couldn't happen to a greater guy.

Of course, Jared wouldn't be Jared if he didn't also come with a huge heaping of neuroses, and Zach Woods plays this to the hilt. Whether it's giving the team pep talks or breathing down the intern's neck, Jared is an integral part of the show's ensemble.

Kumail Nanjiani as Dinesh Chugtai, awkward as ever and trying way too hard to be cool. His insecurities and immaturity are really played up this Season, to almost unrealistic levels. The Tesla subplot was one thing, but that little self-imposed code competition with Gilfolyle really ramped it up. He's become increasingly harder to like as a character.

Martin Starr plays snarky nihilistic Satanist Bertram Gilfoyle with the same deadpan awesomeness he's brought to the role from Day One. While Erlich is no longer around for Gilfoyle to mispronounce his name, I still get the kick out of hearing Gilfyle call Richard "Dick".

And while this Season he continues his longstanding feud with Dinesh, there's also a lot more for this character to do and he plays quite a significant part in the last few episodes.

Amanda Crew as Monica Hall. Monica plays the same role to the team as she has done the past several Seasons - as a voice of reason and support from upper Management. This role appears to have been ramped up in the absence of Erlich - no longer is she even partially defined by borderline sexual harassment from Erlich, there's a certain assertiveness about her I haven't seen before. She tells Gilfoyle to "sit the fuck down", and he does it. And just seconds later, when Gilfoyle delivers one of his snarky one-lines, she shuts him down with nothing more than a withering look. I mean, wow.

I get this feeling that she's gearing up to take Erlich's place in his absence, and I gotta say, they could do a lot worse!

Matt Ross as Gavin Belson, the scheming, ruthless CEO of Hooli. Overall, Gavin doesn't seem to have learned anything from his growth in last Season. He's still megalomaniacal and petty. If anything, he's relapsed and gotten worse. This makes me feel like the entirety of last Season's redemption arc for him was a huge waste of time.

Comedian Jimmy O. Yang as Jian Yang. Oh. My. God. Jimmy O.Yang outdoes himself this Season as he plays the conniving Chinaman with delicious craftiness. That baleful stare, that deadpan snark... there's a whole lot more of Jian Yang this Season and the show's better for it!

Suzanne Cryer has a fantastic Season playing Laurie Bream. Honestly, this is one hell of a capable woman who reveals new levels of human weakness while retaining the impersonal robotic ruthlessness that made her so badass as a character. Cryer really outdid herself here as she portrays Laurie in a new light - as an antagonist, but one who is still somehow likable.

Neil Casey as Colin, K-Hole boss. Comes across as an Erlich-lite - a brash and cocky boss, but very toned down from Erlich levels of hubris. Learns some humility after Laurie Bream ousts him from his own company.

Tzi Ma as Yao, China boss. A scheming business owner who's meant to portray the stereotypical ruthless China businessman.

Ben Feldman puts in a shift as Ron LaFlamme, Pied Piper's lawyer. What can I say, I love seeing this guy on-screen. His involvement this Season isn't quite as pervasive as it was the past couple Seasons, but he milks every moment he gets.

Josh Brener appears once in a while as Nelson "Big Head" Bighetti. Dim-witted as always, his habit of failing at the most basic things turns out to help the team midway through the Season. But I kind of feel his dumbness is overplayed, and his presence kind of forced towards the end.

Tony Winters is Mayor Wilkins of Goldbriar. He does a fair job as the harried politician who accedes to Gavin's demands.

Keye Chen makes a short but welcome appearance as Dang the designer. There's nothing much to say as the actor kind of phones it in. To be fair, he doesn't have a whole lot to do.

Aaron Sanders as Holden the intern. Young, insecure, and utterly terrified of Jared. By the time the Season wraps up, he's been reduced to a quivering wreck.

A.D Miles as Dee Dee.  He's this frazzled gay developer, and the twist is that he's not ashamed of his sexual orientation, but has to keep his religion under wraps. He and Thomas Middleditch play off each other's characters to hilarious effect.

Chris Diamantopoulos is in only one episode as Russ Hannemann, and what a welcome five minutes' worth of fresh air that is. His appearance, seemingly somewhat superfluous with the crassness quota already previously ably handled by Erlich, adds a much needed jab of levity.

Jeff Elam and Gita Reddy as Tom and Viola, bosses of smart refrigerator company Seppen. They're not very technically savvy and don't come across as greedy or vindictive. Even their lawsuit against Pied Piper didn't look like it was driven by malice. It was only Gavin Belson's idea. They see reason pretty quickly though... and mostly because of Gilfoyle's tech cunning and Jared's negotiation smarts.

Chris Aquino as Danny, Sliceline guy turned Pied Piper employee. Deadpan and... well, just deadpan.

Rachel Rosenbloom as Becky, Optimoji girl turned Pied Piper employee. Snarky and also deadpan.

Krishna Smitha as Priyanka, Tesla buyer Indian girl. She and Kumail Nanjiani do a decent back-and-forth at times.

Todd Louiso as Ariel Eklow, the creepy boss of Eklow Labs. Suzanne Lenz as the robot Fiona whom, according to Colin, he's "definitely fucking".
Armen Weitzman is Jeff Washburn the mole. Scruffy, unkempt and totally dazed most of the time.

Bernard White gets in halfway through the Season to play Denpok, Gavin's former spiritual advisor. It appears that his full name is Denpok Singh. Damn, he's supposed to be Indian?! I totally never caught that! Seriously though, unlike previous Seasons, his presence does very little for the show. Maybe he should have stayed gone.

Andy Daly as the unnamed doctor. Well, not so unnamed anymore. It took several Seasons, but now we know his name is Crawford. And this is also the first time he's actually gotten annoyed with Richard - usually he's the one doing the annoying. And it's satisfying as heck. And all it took was Richard's legendary pedant!

Dan Mintz as Dana, CEO of Quiver. Quiet, stiff and awkward. Gives off creepy vibes, but turns out to be pretty misunderstood.

Benjamin Koldyke as Ben Burkhardt, Dana's COO. A rugged, good-looking middle-aged guy who talks a good game (Radical Candor, Ruinous Empathy, etc) but turns out to be a douchebag. His first piece of advice during the Seppen crisis is to throw Gilfoyle under the bus.

Chloe Wepper as Kira Pickford, boss of Optimoji. Compassionate boss to her staff, but with a take-no-shit style of negotiation.

Andrew Leeds as Duncan, boss of Sliceline. Lame and dorky. Richard thinks he's an asshole, but there are striking similarities in the dork department!

Henry Philips as John the server guy. He only has one appearance in the final episode, but boy did I whoop when he came on!

Jill E. Alexander has one appearance as a returning Patrice, who promptly gets fired again. I laughed a bit too hard at that one.

The Mood

Things move pretty slowly the first few episodes, with Pied Piper adjusting to their new office and new crew, and dealing with all the little obstacles that Gavin Belson throws their way. The little subplots sometimes add to the bloated feeling, but towards the last two episodes, things pick up with terrifying speed. It's like all plot points are being crammed into that one last hour of TV. This serves as a shot of adrenaline to what's ultimately quite an exciting conclusion.

What I liked


Richard introduces the guys to the new workspace and their horrified reaction is priceless. Even Gilfoyle is shaken. Gilfoyle! Special mention to Dinesh's histronics paired beside Gilfoyle's quiet snark. That's barely five minutes into the first episode and already Kumail Nanjiani and Martin Starr are showing great chemistry together.


"We're not dicking around," says Gilfoyle when he, Dinesh and Richard are discussing potential new hires. Cut to the above shot. Juvenile? Yes? Worth a chuckle? Also yes.




The graphic work for Sliceline and Optimoji is bitching! I like how the show producers put that kind of effort into the background.



Jian Yang's Chinese translation for "New Pied Piper" is actually "new Happy Internet"!


Well, if you can actually read Chinese, you're in for an interesting time.

That scene where the team confronts Jeff about being the mole. Jared is livid and drops F-bombs. Dinesh is sweetly naive and acts all betrayed. And Gilfoyle? Gilfoyle destroys his computer with a bolt gun, then calmly destroys his guitar just out of sheer spite.

Gavin Belson makes a throwaway remark and his team of sycophants assign it way more meaning than was ever intended. It leads to a sideplot which takes up screen time, but totally worth it in the end.

The entire subplot about Dee Dee being a Christian pokes delicious fun at the real Silicon Valley's liberal hangups. In fact, by extension, the entire show does. Ron LaFlamme and Jared express concern about Richard's possible racism and being gay is considered perfectly mainstream, but Christianity? Cue the hysteria.


Not only was the entire subplot about Gavin Belson's signature darn funny, this shot as he's unveiling the Gavin Belson Signature Box Three to the world... with his arms raised and his head bowed, he really looks like he's lifting up a gigantic penis and straining under the weight. Also, the subtext: Gavin Belson is a huge dick.


I don't know how much effort it must have taken to make Jian Yang's knockoff of Pied Piper to look this lame, but I love it!

The entire segment detailing Gavin's stay in China. He finds himself stonewalled by Jian Yang.
"If oil company wants to buy your house, there is oil underneath."


The final series of twists and double-crosses has to be seen to be believed. Richard wins by exploiting Gavin Belson's utterly predictable penchant for treachery. It's the final nail in Gavin's coffin for now as he loses, once again, to the same skinny geek as he's done for the past several Seasons, and as usual due to his own failings as a person.


That last parting pan-out shot that shows just how big Pied Piper is about to grow. This is their new office. It's a happy ending; well, happier than any ending they've ever had at Season end. This is an unambiguous victory. In fact, their triumph so mirrors the astounding success at the end of Season One that Richard does exactly what he did back then - puke his guts out.

What I didn't

Richard spending 19,000 dollars on vengeance is a little too close to Gavin Belson's Modus Operandi. Not that it wasn't clever or funny, but I thought he'd grown past that jerk phase... and even if he hadn't, it seemed just a little too early in the Season for stuff like that.



I felt like entirely too much time was spent on Dinesh and his Tesla. Yes, even with its relevance at the end of the Season. Gilfoyle's choice of ride was a little more interesting, but still didn't compensate adequately for the sheer banality of the subplot.

Richard acting like a blushing virgin when Ben proposes being his COO. Like, totally cringe-city.

I don't know if this is deliberate, but the Mandarin spoken by both Gavin Belson and Laurie Bream is painful. Mr Yao's English is actually better than their Mandarin. Fuck, Jian Yang's shitty English is better than their Mandarin!


Richard cosplaying as The Pied Piper. Oh sweet Jesus... why?

Holden screaming "lock them up" like a lunatic. Look, I'm all for mocking Donald Trump supporters (and the douchey Hillary Clinton supporters too, while I'm at it), but this smacks of pandering. Can we keep lame USA politics out of tech shows, please?

Gilfoyle and Monica seem like an unlikely pair, but they work very well together. What I don't like is springing their chemistry on the viewers on the last fucking episode of the Season. Come on!

Conclusion


Do I like this Season? That's a resounding yes. Not only do we get more of the same general tech-related hilarity, the team finally seems to be making strides after five entire Seasons of floundering. And when you consider that this Season is missing Erlich Bachmann, that's not a small thing. TJ Miller's absence was felt... but not that keenly.

This Season felt a lot more fast-paced because there were noticeably fewer tiny subplots to keep track of, and most of those subplots actually ended up, like in previous Seasons, contributing to the final outcome. Though I really could have done without the Telsa thing. What an absolute time-waster.

Looking forward to the further adventures of the Pied Piper team!

My Rating

9 / 10

Till the next Season arrives, Kiss My Piss!
T___T