Working with Functions in Scala – Part 1

Scala treats functions as first class citizens. I keep forgetting the syntax for it, so putting it here as a handy reference. This post deals with the following features of Scala:

  1. Anonymous Functions
  2. Assigning Functions to variables
  3. Composite Functions
    Please note that the term ‘function’ here is used to refer to both mathematical functions and programmatic functions. The key strength of Functional Programming languages is the ability to unify both.

Continue reading

An Imperative Programmer beginning with Functional Programming

Couple of months ago, a friend of mine drew my attention to Functional Programming in Scala, a course on Coursera. Having worked for years with the likes of PHP, C, C++, Java and not to mention BASIC before that, I didn’t think much of Functional Programming. Truth be told, when someone mentioned Functional Programming to me, I thought he was talking about C or rather non-OOP programming which didn’t involve Objects(Yes! I admit it! I was a brash naïve 22 year old fresh with a non-CS degree!). As a matter of fact, that was my perception until I took the course (Okay, there’s honesty and then there’s beating a dead horse!).https://i2.wp.com/cantina.co/wp-content/uploads/2011/08/scalaLogo.jpg

So, for the benefit of the uninitiated who happened to accidentally stumble upon my obscure and randomly technical blog, I’ll give the lowdown on Functional Programming … in my own words. Apart from the regular differences between Functional and Imperative programming, here’s my experience with it:

Continue reading

Overheating while gaming? Laptop shutting down? Throttlestop to the rescue

My Laptop has a decent graphics card allowing me to play all the latest games in Low-Medium settings. But it’s been a year and a half since I bought it and with all the traveling I do, it’s no surprise that it overheats quite a bit. Obvious solution is to take it to a vendor and get it repasted i.e. apply thermal gel on the CPU, GPU and clean up everything inside so that the system is well ventilated and not overheating at the drop of a hat.

But that costs quite a bit. And is very involved if you plan to do it yourself. I’m fairly knowledgeable when it comes to hardware, I upgraded the RAM and HDD myself. But after looking at a video on how to do the repasting, I just gulped and gave up any intentions of doing it myself. First of all, I can’t afford to buy a new laptop if I screw it up.

So, the alternative was to get it to the service center and ask them to do the repasting. But that costs a bundle, and you always run the risk of giving it to a clown who doesn’t know what he’s doing.

The final solution that worked for me was Throttlestop that I found while desperately searching on the net to see if there’s any tool that would allow me to underclock my CPU and/or GPU. This thread on notebookreview has been very helpful and is very active. The original author of Throttlestop himself answers questions or concerns you may have. I would strongly urge everyone to take a look at Throttlestop and give it a shot. Been playing Skyrim and Max Payne 3 without any overheatng issues.

Link: http://forum.notebookreview.com/hardware-components-aftermarket-upgrades/531329-throttlestop-guide.html

EDIT: I am honored that UncleWebb, the author of Throttlestop himself, has left a comment below. I highly recommend reaching out to him via the forum link above if you have any questions or concerns. He helped me tremendously when I was starting out with Throttlestop and is incredibly friendly and responsive. As he suggests, you can also try vacuuming the air vent to get rid of some of the dust clogging up your laptop’s innards. But when all else fails, Throttlestop works like a charm.

Open mp4 file in VirtualDub

To open an mp4 file in VirtualDub, you need to convert it to avi format. Both mp4 and avi are containers and not codecs, so the mp4 file you’re using may or may not have a codec that’s supported by VirtualDub. But in any case, converting to avi is definitely necessary. All you need to do is download mp4cam2avi, convert it to avi and try to open it in VirtualDub. My mp4 was encoded in x.264 and I had installed the x.264VFW which allows me to open those videos in VirtualDub. I got this information thanks to this forum thread.

Octave reads CSV into a single Row

Reading a CSV into Octave is fairly simple. You can use the following command to specify the filename, separator and the array to load the data into. Just make sure you don’t have any headers in the file otherwise Octave will create a row of zeros instead.

data = dlmread(“test.csv”, “,”);

But if you find that Octave is reading everything into a single row which is filled with gibberish, it’s probably an issue with the end of line (EOL) encoding. In my case, the CSV was encoded with a Mac EOL. Octave is comfortable only with Windows or Linux EOLs.

Converting is fairly easy. Open Notepad++ and select Edit->EOL Conversion->Windows Format or UNIX Format. That will fix the problem.

image

Truth table for implies

We would normally use (A implies B) as a conditional statement and not so much as a statement that is true or false. But apparently in many cases it is considered as a logical statement which can either be true or false. The truth table for (A implies B) or (A=>B) is given as follows:

A B A implies B
T T T
T F F
F T T
F F T

 

It’s quite difficult to wrap your head around this. I’ve tried a lot and have now accepted it for what it is. I’m sure I’ll get round to it sometime in the future and when I have more clarity about it, I’ll post here. For now, understand that it’s identical to evaluating ((Not A) or B)

A B Not A (Not A) OR B
T T F T
T F F F
F T T T
F F T T
One way to remember is like this –
  • If A is False, then it doesn’t matter what B is, A=>B  will always be True
  • If A is True, then A=>B will be True only if B is also True.
    Think about this and leave a comment if you have anything to add.