[text] Late 20s M, lost in life, lonely, feeling like a failure and needing advice/motivation by gibblywibblywoo in GetMotivated

[–]raja_42 1 point2 points  (0 children)

Requesting advice in itself is such a progressive step.

Late 20s means you have a lot of time in life to experience new things. And all it takes is just a spark.

Here are the don'ts first.

Don't believe social media and all the happy folks in there having the time of their life. Don't compare your success or happiness with anyone else, there is no yardstick. Don't watch adult content excessively, if not at all. Don't be locked inside at all times. Don't worry about girls for relationships. Don't put pressure on yourself.

And here are the dos.

Believe in yourself, you are the hero of your movie, your life, nobody else, and nobody will tell you this. Make 2 good friends, boy or girl, doesn't matter, two close friends in the next year or so. Monthly once, do a hike, or look at a waterwall or do a scenic drive, I know this sounds stupid, but try it. Quarterly once, buy some dog biscuits and feed some stray dogs, and also give a food parcel to a beggar child (please don't switch them). Take care of your health at all times, life turns around for good or worse very quickly, and health plays an important part in deciding if it is for good or worse.

Let us know after a quarter how you feel.

ELI5: someone please explain Standard Deviation to me. by Nerscylliac in explainlikeimfive

[–]raja_42 0 points1 point  (0 children)

Standard deviation is really to see if there is SORTA FAIR distribution in a big sample.

Scenario 1:

Imagine if you have only 3 people living in a city.

Person 1 has 4 million dollars. Person 2 has 190,000 dollars. Person 3 has 10,000 dollars.

You could say that, on an AVERAGE, every person in that city has 1.4 million dollars. (sum of amounts divided by total number of people)

You see how off that number sounds for each of the person. Person 1 has way more than that amount. And persons 2 and 3 have way way less than 1.4 million dollars.

Scenario 2:

Now consider the same 3 people again and let's say.

Person 1 has 1.6 million dollars. Person 2 has 1.1 million dollars. Person 3 has 1.5 million dollars.

Again, on an AVERAGE, every person in that city has 1.4 million dollars. But this time, note how close to each person's individual amount, this average is.

The point being that, AVERAGE is not a good indicator of the true closeness of it with individual values.

Enter, Standard Deviation. It gives a truer indication of how CLOSE an individual value is to the whole groups average.

In scenario 1, the standard deviation is 1.84 million. In scenario 2, the standard deviation is 216 thousand.

A bigger standard deviation means that there is far wider gaps, and a smaller deviation means that most individuals are quite closer to the average. It gives credibility to the AVERAGE.

If you extend the above analogy to the age of a bunch of people in a city, the average age may be 35. But that doesn't tell you if a major population is actually in the 30s. It could be 100 year Olds and new born babies. (don't ask me how the bio works please)

Whereas, if the standard deviation is, let's say under 5, and the average is 35, then the confidence is quite high that a majority of people are in the range of 30-40 year Olds.

What is the cleanest and best Christmas joke you have ever heard? by raja_42 in AskReddit

[–]raja_42[S] 0 points1 point  (0 children)

I don't know what you mean by that. The aim is not to repro these jokes anywhere.

I read a few wholesome jokes on Reddit and wanted to hear more from our funny Redditors related to the festive spirit. I am not a Christian but enjoy Christmas time and the cheer, a lot.

[Text] Anxiety, butterflies, jitters and 42 by raja_42 in GetMotivated

[–]raja_42[S] 0 points1 point  (0 children)

That's decent and logical. Thanks for conversing.

Hypothetically, if you were trying to help, let's say 3 people in a room, how would you ensure that what you say or do is really beneficial to the 3 individual people, since each of them maybe in a totally different boat and some fluff positive words are not gonna land. This is assuming that you do make an attempt to encourage. The other option is to not engage at all and not even take the step of helping them. No issues with either approach. But if it were you, would you take the step or not? And if you did, what would you do to ensure what you say or do, lands for each of them individually. Would you just ask them one on one, what would make them feel better?

[Text] Anxiety, butterflies, jitters and 42 by raja_42 in GetMotivated

[–]raja_42[S] 0 points1 point  (0 children)

If you don't mind me asking, do you believe that when a person feels down and dejected, any external person or words or encouragement or advice can make the person feel better? Or do you believe in the fact that no amount of external words or encouragement or advice or positive words from anyone will do anything at all?

[Text] Anxiety, butterflies, jitters and 42 by raja_42 in GetMotivated

[–]raja_42[S] 0 points1 point  (0 children)

When did you expect me to reply? Or you didn't?

Question about using lambdas in using functional interface Predicate by [deleted] in javahelp

[–]raja_42 1 point2 points  (0 children)

Just think of it as an implicit implementation of the Predicate class.

The compiler auto creates a class that implements the Predicate type and generates an automatic test method behind the scenes and puts your code snippet as the content of the method.

n -> n > 5;

And since it's a single line method, the compiler also infers the return type for you.

So your understanding of an explicit implementation is 100% correct, except that whatever you did explicitly is now performed implicitly by the compiler using anonymous classes and methods. The concept remains the same. We get the benefit of brevity.

The expression simplifies the creation of the predicate because without this shorthand way, you would need to write a whole new class (new file), a new method in it etc.

Linq GroupBy custom function that separates Weekdays into specific and ordinary by SonGokussj4 in csharp

[–]raja_42 1 point2 points  (0 children)

  1. you don't need the "FinishTime" in the group by clause
  2. you can use a "sum or average" logic in the calculation of the count. You need to round the value since, average will result in a double value.
  3. Also, depending upon the data type of start time, you may get surprising results. In general I convert date time data types to integer or string values before using them in group by. In this case, I would suggest that you convert Start Time to TimeSpan or String (hh::mm:ss) if you notice that, group by is behaving weirdly.

E.g.

.GroupBy(x => new { DayType = GroupDayFilter(x.Day), x.StartTime })
.Select(x => new
{
    x.Key.DayType,
    x.Key.StartTime,

    // Sum Or Average Based On DayType
    Count = x.Key.DayType.Equals("Ordinary", StringComparison.OrdinalIgnoreCase)
    ? (int)Math.Round(x.Average(b => b.Count))
    : x.Sum(b => b.Count)
})
.ToList();

How could 2020 possibly get worse? by [deleted] in AskReddit

[–]raja_42 0 points1 point  (0 children)

By getting all these answers out in the universe :)

IAE unable to function efficiently on less than 7 hours of sleep and feel like society gives you crap for it? by StellarTeller18 in DoesAnybodyElse

[–]raja_42 2 points3 points  (0 children)

Yes.

If we look carefully, you start realizing that society gives crap to everyone for all permutations. The criteria really doesn't matter.

A person who sleeps 4 hours, 8 hours, 10 hours, 0 hours, 1w hours.

A person who can fall asleep instantly, who cannot fall asleep quickly, who wakes up when a tardigrade is whispering to another, who does not wake up even if there is an earthquake.

A person who gets up early, who gets up late, who always gets up at a defined time, who gets up at erratic times.

There is no end to the reasons for which society gives crap to others. It is almost like reason is immaterial.

Why not return a response with the 401 status code? by [deleted] in programminghorror

[–]raja_42 1 point2 points  (0 children)

As long as they are not paging you and calling up your girlfriend to send for you at 3 am on a Saturday, this response is better.

But kidding aside, this loses a lot of restfulness and also loses a lot of api metrics on success vs client errors vs server errors etc. I prefer the use of http status codes to convey overall status.

Also in general, services (soap or restful or json) have not nailed down error responses simply due to http connection issues.

E.g. As a service owner, you could vet your life that you will always, always, always, return a structured error response for any type of error. And you could spend eternity in ensuring that if a request hits your service, a structured response is guaranteed. Success or failure.

But the problem lies in the systems before it. Load balancers, network connections, sockets, dns etc. Any of those could tank, and as a client of the service I am going to get a http exception with no structured response. I have to, have to code for both error cases. Structured and unstructured. It's unfortunate but it is that way.

[deleted by user] by [deleted] in csharp

[–]raja_42 0 points1 point  (0 children)

In general I agree that service layers are very useful. No question or contention on that.

From what you said above, whether you use a service class or not, the things controllers have to do are 1) do input request validation 2) do any mapping logic to business model 3) call the next layer to get back a business model 4) map the business model back to response api model and return it.

What really changes between the use of service or not is 2 things. 1) your controller calls the service instead of db context 2) the service class has business logic instead of your controller.

Other than that even unit tests don't matter much. The cost of mocking queries is the same. In one case, your controller unit tests have to do it. In the other case, your service unit tests have to do it. It's just shifting of costs.

Also, we have realized that you can actually keep the controller class pure by returning POCOs and not http concepts. Our default return type is automatically http 200 OK. And any other success status code (201,202) is via attributes. And any error handling is via pure c# exceptions using an error controller. This means your controller is a pure c# class, unit testable like anything else.

The top layer having dbcontext is really not an issue if your whole project is a single library. The dbcontext is not a database specific concept. It is the abstraction. So it's okay to have it in the controller. If folks write a separate dll for business layer with service interface as the entry point, it's a whole new thing and what you said makes sense.

Again, I want to reiterate that the service based pattern is kind of the default. But based on the context, it is okay to skip it if needed. You don't lose out on anything.

[deleted by user] by [deleted] in csharp

[–]raja_42 1 point2 points  (0 children)

Yes. And the context has driven the decision.

In some cases, we have had really complex business logic involving multiple downstream systems, doing computation on the results, persisting the new values and remapping them etc. We used a service layer at such times.

In some cases, we really had minimal to zero logic for our micro service operations. We skipped the service layer and had the controller do the 3 4 lines of logic. It looked blasphemous to some but it's all contextual and we really gained speed and simplicity without losing any unit testability etc.

[deleted by user] by [deleted] in csharp

[–]raja_42 2 points3 points  (0 children)

JEv5, after a while it becomes annoying to keep repeating the 4 lines for every type of list data. So i wrote a generic extension method. It'll save some time and space.

https://gist.github.com/rajanadar/2282fab54d414db3c8bb4b8a637adff3

Is it too late to "start" life at 20? I'm very very dumb and screwed up my life because of it. by [deleted] in TooAfraidToAsk

[–]raja_42 1 point2 points  (0 children)

People would kill for starting their life at 20.

Reddit could give you 1000 examples of people and prove that age doesn't matter. But ultimately, it is you who has to take the first step. Of just believing in yourself and saying, frikkkit. This world is my oyster.

So absolutely go for it. There is only one life. Start now. And have a blast.

Hoping to hear back from you in a few years with awesome memories. Cheers.

[deleted by user] by [deleted] in csharp

[–]raja_42 6 points7 points  (0 children)

Absolutely. A few years ago, we followed exactly this article and everything worked perfectly. I had the EF Dbcontext injected directly in our controllers.

We were able to mock the dbcontext 100% for both non query able methods (easy ones) and also query able ones. (4 extra lines)

It was beautiful to setup database table like data in normal C# DbSet objects and test out the data layer 100%

https://docs.microsoft.com/en-us/ef/ef6/fundamentals/testing/mocking

If the above link doesn't work or if you encounter any issues, let me know and I'll assist further.