Wednesday, August 24, 2011

HOWTO - Creating a resharper file template





I recently created a Resharper file template that simplifies for me the process of adding a new Test class in a test project and gets me directly to the point where I can start writing the test [without doing any of the boiler plate stuff]. Here is a simple DIY manual for creating a Resharper file template. This is essentially a template for creating a nunit test fixture.
We notice that there are redundant actions that you have to perform every time we want to add a new test class to our project. I therefore want to have a template that does all the plumbing work for me whenever I want to create a new test.

Click on the "Resharper -> File Templates" menu in Visual Studio.
Select the "File Templates" tab in the window that appears and click on the +Add Button
Resharper next displays a create new template window. 

In the Description, add a name for the template(I admit this is oddly named). And in the text area to the bottom left, add the content that you want your template to fill out for you automatically. My template looks like this. 

 Notice the identifier(the rich tokens surrounded by the $s) and the replacing macros to the right of the template body. Resharper allows you to choose the macro that you want simply if you click on the 
Change macro... link. Choose the one that makes most sense to you. 






Tuesday, August 16, 2011

Resharper FileTemplates FTW!!





Sometimes, when you are pairing you feel the need to be more precise in the way you write code. You might want to generate the same amount of code using lesser keystrokes. This has a few un-obvious advantages:
  • that your pair is not going to have to sit bored as you keep pecking on that keyboard
  • with lesser keystrokes, you’re going to write code quicker(duh),
  • with lesser keystrokes, you have fewer errors.
  • You look cooler and more sophisticated.




Even the fastest typists I know are like hulk when it comes to coding - All brawn(Like Hulk). Coding is not just typing. Its more sophisticated(Like Flash).


Normally, creating a test class in c# would involve the following steps.

  1. Navigating to the folder where you want to put your test file.
  2. RightClicking on the folder and clicking add -> Class
  3. Giving a proper name for the test class.

  4. Adding a using NUnit.Framework; line of code at the top of the file
  5. Marking the class as [TestFixture]
  6. Adding [SetUp] and [TearDown] methods
  7. Finally, you get to the test and get to the arrange, act, assert tradition.
One such feature in Resharper is File Templates and its darn useful.

To illustrate, lets try writing a basic Test Class with a basic test and see how many steps it takes.


Alt+Insert on a folder and selecting Test
 




Giving the new Test Fixture a proper name

Voilla


PES - Project Euler 9

A particularly interesting feature of f# is its lazy types. A lazy type is something that doesnt get executed all the time. It gets evaluated only when necessary. At all other times it just gets passed around. In this problem, the objective is to find a particular Pythagorean triple .

Here is a function that calculates a Pythagorean triple given m and n such that m > n.
    let PythagorTriple m n =
            m*m - n*n, 2*m*n, n*n + m*m

Friday, July 1, 2011

DBNull and null

I am deeply frustrated at this point in time. The reason is because I have been spending the last 30 minutes hung over a very careless mistake. C# has the coalesce operator that allows you to write code that looks neater when you are doing complex stuff like LINQ. The problem looked something like this - I had to read a couple of rows from the database and convert those data as properties on an object.
the code would look something like this:

object x;
int value;
if (x == null)
  value = -1; // default value
else
value = (int)x;

The coalesce operator allows you to make the code more concise by saying

int value = x ?? -1;// less code = less maintainence

but whilst reading data from a database table, if a particular cell is a null value, it is not read as a null but it is read as a System.DBNull. So, the freaking row[field] read was getting read as a DBNull. Once I noticed that this was the problem,  I coul;d fix the code, but the fix was less elegant.
More edits on this post when I find more about it.

[Edit 1]
Found this related question on Stackoverflow [here]


Monday, May 23, 2011

Saturday, May 7, 2011

hello blog

Finally, I figured out a way to post code onto my blog. Thank you @CraftyFella

// Comment
public class Testing {
public Testing() {
print("WooHoo");
}
 


Inequalities

A couple of hacks to get done with Inequalities problems on the GMAT quickly. These might not help you to solve the entire problem. However, these can help you to reduce the amount of time spent in evaluating answer choice, specifically for DS questions.

|x-5| < 2
How do we interpret the above (in)equation? The normal/longer root would be to solve for two equations - one treating the outcome of (x-5) as positive and another treating the outcome of (x-5) as negative. Thus the two equations you would solve would be for (x-5) = 2 and (x-5)= -2 and then finally, replace the "=" with a "<".

A shorter, easier, less error prone method would be to rephrase the (in)equation - read it as x is less than 2 units away from 5. Reading it this way, the answer instantly pops out that x can take values from 3 to 7

Original inequation Rephrasing Range of x
|x+5| < 2 x is less than 2 units away from -5 from -7 to -3
|x+5| < 2 x is greater than 2 units away from -5 from -inf to -7 and -3 to +inf

Saturday, April 30, 2011

Numbers on steroids #2

Yet another GMAT Hack:
What is the mean of the numbers on an arithmetic series a, a+d, ...., a+(n*d)
If we take the last numbers as l,
then the mean  = (a + l)/2.
Nifty Huh?!

Numbers on steroids

AS some of you are aware, I am trying my hand at the GMAT. Nothing serious. I was just bored over a couple of weekends. I Didn't have any code to write so I decided that I was going to write the GMAT. These are three properties regarding perfect squares which I learnt about and I am putting them here for any person who is writing the GMAT. All right I am putting it down here so that I can google myself up later.

These are the props :
  1. A perfect square has an even number of powers of prime factors
  2. Any perfect square integer always has an odd number of distinct factors.
  3. For any perfect square, the sum of its distinct factors is always odd
Now for the substantiations: 
  • A perfect square has an even number of powers of prime factors
This is "THE BASIC RULE" and the other two (and perhaps many others) rules can be derived out of this rule. The rule says - For a perfect square, N, if N is prime factorized, say N = (px) * (qy), x and y can and will only be even integers. This seems pretty obvious. If x and/or y were infact odd, there wouldn't be able to find  sqrt(N) in an even positive integer.

With  that now settled, in order to prove the second point,

  • Any perfect square integer always has an odd number of distinct factors.
there is this tiny hack that lets you find the number of distinct factors a number has. it is a simple two step process. 
  1. Factor the number into its prime components, N = (px) * (qy)
  2. The number of distinct factors =(x+1)*(y+1).
Since we proved just now that for such a perfect square x and y will be even,
 the number of factors = (even + 1)*(even + 1)
                                    = odd* odd
                                    = odd

 The third rule is a bit tricky

  • For any perfect square, the sum of its distinct factors is always odd
I havent arrived at a thorough proof for this one as of now. But one thing to remember is that any perfect square will have an odd number of odd factors and an even number of even factors. So adding all these up, we get an odd integer. Try it. 

Sunday, February 13, 2011

Wednesday, November 17, 2010

F#un

I have been trying my hand at trying to learn a new functional language for the past some time and I made a pretty decent choice of F#. Since I am currently working as a .NET developer, I find F# tons more comfortable than other languages such as Clojure, Haskell or OCaml. I intend to get a deeper understanding of the language by solving problems from Project Euler. Solutions to follow :-)

Friday, February 5, 2010

Retrospective after BAD(I mean "BAD") Bowling

Finally, after many light years, an interesting thought actually worthy of being read on a blog has entered the trenches of my mind(Or at least I choose to think so). The ThoughtWorks University batch went bowling yesterday and I learned one thing from the experience --- I SUCK at bowling.

Saturday, January 9, 2010

My fir_______

I originally started to write this post as a draft of my experiences at the ThoughtWorks Orientation . But later, it crossed my mind how blogs and digiital reading take out the real content out of a narration. Take a second how a story is read on the screen. Is it really a story?
Is something missing from it?
I think the problem is that the story gets transmogrified , or belittled into information . A story posted no longer remains a story. It gets converted into a few kilobytes of 1s and 0s. Is it just me who feels this way?Share your thoughts on the way you feel about digital reading

Saturday, January 2, 2010

Friday, December 11, 2009

Friday, November 27, 2009

watching movies in the reverse

Ive started this new experiment on how you would feel about movies if you watched them in the reverse.. Ive just got started . Please leave your comments on other movies that you would like to be included in this space

THE KARATE KID:
When watched backwards - A movie about a brave guy who turns into a wimp and moves back to new Jersey.



JAWS:
When watched backwards - A movie about a shark that repeatedly throws up people until they open up a beach for swimmers.


MEMENTO:
When watched backwards - A movie that finally makes sense.

COMMANDO:
When watched backwards - A movie about a retired commando who hands over his daughter to the bad guys, fights in world war 3, and the gets her back.

Kung Fu Panda:
When watched backwards - A movie about the dragon warrior , unlearning the art of Kung fu, Bouncing up the thousand ladders repeatedly , fighting Tai-Lan who after beating up the panda goes and locks himself up in the ostentatiously guarded prison. The panda then goes back to making noodles for his dad.

Byte club

Friday, June 5, 2009

There i go again...

What we know as intellectual truth, is that also not a perfect rhythm of the relationship of facts that produce a sense of convincingness to a person who somehow feels that he knows the truth? … We believe any fact to be true because of a harmony, a rhythm in reason, the process of which analyzable by the logic of mathematics. “

- Rabindranath Tagore

Friday, May 29, 2009

Song_Review:Beautiful-Akon

Rarely does a song come by that makes your ears cock up and take notice. beautiful is one of those songs. To all those of you who thought that Akon couldn't out do his 'I wanna love you' or 'Lonely' , this song comes out as a bolt from the blue. The song has followed in the same footsteps as I wanna love you, but this time, It is less vulgar(At least , It doesn't have Akon singing I wanna f**k you!)
The flow is smooth and subtle and the background instruments couldn't get better(Again! Akon, May out do this one more time and I take no responsibility for the long term authenticity of the above statement). The song features kardinal Offishal(Where did this guy learn to spell?)and a guest appearence by the Mozart of Madras- ARR himself.
In spite of the lewd lyrics rendered to this piece by Offishal(Thanks a lot dude, this is just what we needed in a romantic love song),The song still maintains a high level of a good feel.
Beautiful - The song is beautiful in all aspects

Interna? naana?

Well, This was the reaction of a lot of my class mates to the shocking news about vangal and I getting interned at a company in Madras against the backdrop of the Global Economic recession.
We knew it was too good to be true. For starters, it was not a job that was in the remotest of senses-ENJOYABLE. Let me give you an idea of my job Description - I read, I copy, I paste , I provide citations. My day at the office typically starts around 9:30 and my colleagues find my working style rather amusing.I practically work between trips to the water cooler.
The way i work? Copy, Read, Paste, Water cooler,Copy, Read, Paste, Water cooler, Copy,Water cooler, Paste , Duplicate, Read Ashwin anna's blog, Water cooler, Read Umesh's blog, lunch,Logical puzzles,Copy, Paste, water cooler and so on......
The job got so monotonous, that for the first time in my life, I heard of job drop outs. True, about 8 guys from the same college as I quit almost unconditionally after the second week. It was during the last day of the second week that something miraculous happened- -my boss- asks me to work on web Development. it sounded like a sine wave at 19,999Hz.(The highest frequency a human can hear - I still remember my physics and Ive got good reason for it too..)
the first module that I was supposed to work on- It was for judging the popularity of the published content. And guess what that was called ------Radioactivity. It used the same principal. Posts which are actively viewed gain heat, Posts which are passive get colder. You might say, that was a my high point for me at my intern. Just the next day, My boss walks in
on me and sees me playing around with one of the modules on the site development platform. He says that it is an important part of the website and asks me to do it top-notch ....... Again 19999Hz, . Im not sure if my ears can take it any more.
Ive got one more week to finish the modules assigned to me , and Im confident that I will have completed it by tomorrow. Who knows what the next week has in store?