Category Archives

33 Articles

English/Technical

c# using custom attributes to validate prerequisites for methods, controller APIs

Posted by chavakiran on

If you have bunch of prerequisites to be validated for more than one method, we could make code more cute by using an attribute.

For normal methods, this new custom attribute’s constructor could throw exception in case of failure.

But throwing exception in Controller API is bad idea. We want to return more gracefully.

Instead of extending Attribute, extend AuthorizeAttribute and override IsAuthorized() [ or AuthorizeCore() ] method to return true or false. This is more graceful way of doing prerequisite check.

I know this AuthroizeAttribute is to check authorization, but we could mis-use it to validate any prerequisites until a better way is available.

/*****************************************************************************************/

using System;
using System.Web;
using System.Web.Mvc;

namespace WebApplication1.Controllers
{
internal class MustBeAuthorizedAttribute : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{

if (preRequsitesFail)

{
return false;

}

return true;
}
}
}

/*****************************************************************************************/

[MustBeAuthorized]
public ActionResult Index()
{
return View();
}

/*****************************************************************************************/

Thanks to @philip instead of AuthroizeAttribute  ActionFilterAttribute is better. We could return any return value (e.g.. MethodNotAllowed, InternalServerError); see https://stackoverflow.com/questions/16822365/web-api-how-to-stop-the-web-pipeline-directly-from-an-onactionexecuting-filter 

English/Technical

notes, unit testing c# mock, stub, shim!

Posted by chavakiran on

What to unit test?

Some times it feels why the heck are we adding this unit test? Some times did we really added at least minimum required unit tests or not?

I spent good amount of time researching this topic.

My thumb rule is :

Assume you are adding a document with samples directly taken from Unit tests (except Mocking part though) ; We want our Unit tests to test what customer typically do.

Unit Test is a shield:

Unit test works like a shield. It protects from the minute it is born. This unit test shield will protect the code from your future self. This unit test shield will also protect from others working on this piece of code. Mistakes which will break some existing user can be avoided with this unit testing strategy.

Mock Vs Fake(Stub/Shim)

Use whatever works! External DLLs are better faked. But there are some beasts which will have give tough fight to be faked. In that case do not directly call this external DLL, rather call via a thin layer, a layer with zero business logic but with an interface+class design. Then mock this layer instead of trying to fake your external DLL. Unit tests are saved!

English/Ideas for better future

Idea : Rating Display Card for retail shelves

Posted by chavakiran on

One big difference between online Vs offline retail shopping experience is its rating experience.

Why not retail shelves include a rating card for for all its items on shelf? Customers can view current rating and enter their rating.

It is challenging, but not impossible.

Some of the challenges

1. How to avoid duplicate rating ?

2. How to authenticate users?

(Adding Finger print based rating will solve both above problems. Again which finger? How sensitive is this finger print data? What are security/privacy implications? How to provide accessibility? )

But all these are solvable and fun to work on.

arate

——

Background : I purchased a scrub in QFC (supposed to be better than the one we buy in costco), it cleans OK like in between steel scrub vs sponge scrub but thats where the goodness stops, it spoils everything it touches! For some reason it puts dirty marks on the sink and floor. If the same item is purchased in any online store, I might have read reviews/ratings and may not have purchased the same.

Business Idea/English

Idea : Health Insurance for 65+

Posted by chavakiran on

Apparently one of the biggest concern for retiring is rising health costs.

What if there is a company which collects nominal insurance premium for < 40 years people until they become 60 and starts giving health insurance with zero premium from 65+ ?

Company had more than 25 years to make enough profits on the pre collected premiums.

Company can put restriction of maximum cap on insurance amount per year (Like they do in India) That way it can minimize risk and calculate its costs with confidence.

English

USPS use of technology is crazy! (on a good side)

Posted by chavakiran on

USPS – now you can simply check incoming mails including the photo of the letter from your computer or mobile! Cool. You can visit your mail box only if the letter is important. Easy to ignore those spam covers Smile 

I am pretty sure, all this is automated!

Imagine millions (Billions?) of letters scanned, address is (OCR) recognized, categorized and visible to owner.

Whoever first got this idea Kudos!

English/Poetry

This is now completely different

Posted by chavakiran on

This is now completely different,

a magical transformation.

An urban setting into rural-

A rural setting into urban.

Like black into white,

like white into black.

Shredding all gray on the way,

This is magical transformation.

Readying journey onto distant worlds,

igniting boosters with pure will power,

taking whole families along with it,

including their hopes and passions.

This is just begging of

exciting journey towards more magic.

Make no mistake,

this is not what you know,

this is nobody named yet,

only those part of it,

can experience this wonder

until ballads are sung,

until books are written,

until case studies are made

nobody knows the magic.

Cooking/English

Guacamole a must try snack for Indian taste buds 

Posted by chavakiran on

First time I saw these in USA supermarkets I am clueless of these fruits. But in frenzy to try new things I bought a bag of these Avocados from Costco. Still clueless what to do with them. They stayed on shelf for a week and became ripe and ripe Avocados looked gross to me. I couldn’t bring myself to try anything with them. My wife is more conservative when it comes to food. She didn’t even pretended to acknowledge their presence but moved them to fridge. After two weeks on a fine Sunday they were relocated to trash. 

Things might have stayed same if not for a visit to Chipotle with cousin. I loved Guacamole. I my God I don’t believe it is not Indian version of some Chat. 

Then did some Google search about guacamole recipe. Surprise! It is made from Avocados. 

To be careful this time got only one Avocado from tradersjoe. Followed instructions. Did video search about how to peel this fruit. 

Pretty easy and delicious awesome evening snack. Loved it with tortilla and even Karappoosa. 

Recipe 

Just cut onions add Avocado squeeze a fresh lemon add coriander leaves. Optionally add a pinch of salt a d couple of green chilies. Mash it to your liking a d eat with tortillas. 

Usually takes 30 minutes 

English/Telugu Cinema

How to understand this madness of Chiru Vs Balayya or Khaidi 150 Vs Satakarni

Posted by chavakiran on

The majority of the Telugu folks across the globe are ignoring the upcoming Sankranthi movies, but at the same time vocal minority proactively taking things to peak madness regarding the upcoming two movies of this Sankranthi 2017. One is Khaidi No. 150 coming from Chiranjeevi the other is Gautami Putra Satakarni coming from Balakrishna.

For any sane person this doesn’t make any logical sense. So, how to understand this insane mass hysteria?

To understand this, we need to look at human beings at all places, not only Telugu folks. Human beings always need some roll model, be it gods, heroes, knights or kings. May be it is something we inherited from animals, follow the strong, emulate the strong, survival instinct. Those who followed strong, those who emulated the strong survived and passed their jeans successfully, along with the jeans the same traits passed on.

What if we don’t want to be part of this madness? May be we will become extinct just like countless others in the past for millions of years. Better thing to do is to redirect our energies to some other exciting thing. So what is that better positive thing? (Leave a comment with your ideas….)

And the Yandamoori Vs Nagababu Vs Varma episode. Any publicity is good publicity. People should talk about us, what they talk doesn’t matter. I believe this is a simple marketing gimmick. A well scripted, acted, played one. Best thing is ignore it. don’t become part of it (Alas! Just like I did in this para)

Movie is powerful tool. A society which uses it carefully, advances exponentially. For the past fifty years, Telugu movies played commendable role in the progress of our Telugu society. Every decade they played vital role in directing Telugu energies. They have subtle narrative of our manifest destiny. One of the reasons for BIMARU states backwardness is lack of independent movie industry! But now for the Telugu movies, the path seems to be diverging away from its overall positive role in setting future narrative, and the gap is increasing. I hope  our creative directors will take things in right direction by following their heart, by being independent, by being calculated capitalistic. Let us keep watching the movies and be part of our tribe!

See you after Sankranthi with two reviews 🙂

Does people forgive Chiranjeevi and accept him back as a hero rather than a failed politician who settled things only for elite around him and ignored completely about the voters who voted for him.

Does people accept Balakrishna in the most powerful character of recent past even with Director Krish magic?

Fingers crossed.

What do you say?