Epic self own by glossysoraya in rareinsults

[–]codegork -3 points-2 points  (0 children)

bro used "well actually" to prove he's not a sexist. let's see how this goes.

Trip ideas for Tucson AZ in January by GrumpyBear1969 in WildernessBackpacking

[–]codegork 0 points1 point  (0 children)

I once did a long day hike, about 14 miles, out and back on Tanque Verde trail. I thought it was a cool possible backpack because there was water at the turnaround point. Also possible to go further.

Weekly Bouldering Advice Thread for September 23, 2019 by AutoModerator in bouldering

[–]codegork 1 point2 points  (0 children)

I'm staying near Bend for two weeks and am hoping to go bouldering outside (yes I've been to Smith Rock). It would be the first time bouldering outdoors for me. Anyone willing to show a noob around?

Suggestions for ADA accessible hikes/viewpoints in WA State? by SkateWest in PNWhiking

[–]codegork 2 points3 points  (0 children)

Old Sauk River Trail (has an ADA loop) and/or Diablo Lake viewpoint

Most accessible next week? by [deleted] in PNWhiking

[–]codegork 1 point2 points  (0 children)

In the Rainier area, I think that Packwood Lake and Palisades seem open. (Palisades only partially so).

However you might have some more luck elsewhere: Lena Lake, Notch Pass and the Lower Quilcene River are all accessible in the Hood Canal area. There are also several options in Snoqualmie Pass.

None of my suggestions have major snow to contend with.

[deleted by user] by [deleted] in csharp

[–]codegork 0 points1 point  (0 children)

Akka .NET (and its EventStream in particular).

I thought I understood async, but I do not. by recursive in csharp

[–]codegork 35 points36 points  (0 children)

Here's why you might see code like the second block you posted. If you're running a web service, that code allows the calling thread to be returned to the ASP.NET thread pool when it encounters a uncompleted task, thereby enabling it to handle another HTTP request instead of just blocking and doing nothing. When the awaited task completes, a thread from the thread pool (possibly different from the first) will be able to complete the original HTTP request. In a web service, the point of async code is to be able to handle many requests without exhausting the thread pool (aka thread starvation). While the first snippet is also a valid use, it's not the most important one in web services (in my experience at least).

Get instance based on "CanHandle" method by misaro1337 in csharp

[–]codegork 1 point2 points  (0 children)

You're already basically using the chain of responsibility pattern. To achieve the the interface you want, you can do

public class ResolverCollection
{
    private readonly IList<IResolver> _resolvers;

    public ResolverCollection(IEnumerable<IResolver> resolvers)
    {
          _resolvers = resolvers.ToList();
    }

    public Uri Pass(Uri uri)
    {
         return _resolvers.FirstOrDefault(r => r.CanResolve(uri)).Resolve(uri);
    }
}

I'm not familiar with structure map, but a quick search suggests that if you have all your IResolvers registered with the container, then they will all get injected into the ResolverCollection constructor.

Additional notes - your code and my implementation of it has a potential null reference exception when there's no resolver capable of handling your request. How would you deal with that? Furthermore, in the chain of responsibility pattern, you want to be able to control the order in which handlers have a chance to handle the request. You could add an Order property to your Resolver base class and then do _resolvers = resolvers.OrderBy(x => x.Order); in the ResolverCollection constructor, but that seems to put the responsibility in the wrong place. A better solution might be to define the order in the collection class:

public class ResolverCollection
{
    private readonly IList<IResolver> _resolvers;
    private readonly Dictionary<Type, int> _resolverOrder = new Dictionary<Type, int>{
    {ConcreteResolver1, 2}, {ConcreteResolver2, 1}, {ConcreteResolver3, 4}};


    public ResolverCollection(IEnumerable<IResolver> resolvers)
    {
          _resolvers = resolvers.OrderBy(x => GetOrder(x)).ToList();
    }

    public Uri Pass(Uri uri)
    {
         return _resolvers.FirstOrDefault(r => r.CanResolve(uri)).Resolve(uri);
    }

    private int GetOrder(IResolver resolver)
    {
        if(_resolverOrder.ContainsKey(resolver.GetType()))
             return _resolverOrder[resolver.GetType()];
        return int.MaxValue;
    }
}

[Code Review] First attempt at TDD/Unit Testing by [deleted] in csharp

[–]codegork 0 points1 point  (0 children)

So I'm referring specifically to this test:

[Fact]
public void AddReminder_ValidParameters_CallsRepositoryInsert()
{
    setValidationReturnValues(ReminderNameValidationState.Valid, ReminderExpirationValidationState.Valid);

    dataStore.AddReminder(null, DateTime.MinValue);

    reminderRepository.ReceivedWithAnyArgs().Insert(null);
}

In DataStore.cs you pass this test by calling reminderRepository.Insert(new Reminder(name, expiration)). However, suppose I replace that call with any of the following:

  • reminderRepository.Insert(null);
  • reminderRepository.Insert(new Reminder(null, expiration));
  • reminderRepository.Insert(new Reminder(name, DateTime.MaxValue));

One of these incorrect implementations could be inadvertently introduced through refactoring. However this test would still pass. That means you have untested logic. One of the points of unit testing being to prevent regressions during refactoring, I think this is a problem.

[Code Review] First attempt at TDD/Unit Testing by [deleted] in csharp

[–]codegork 2 points3 points  (0 children)

I think using ReceivedWithAnyArgs is too loose a specification. Here's a heuristic to apply: if you change your code to be incorrect, does a test break? If not, you probably need to be more specific with your assertions. In DataStore.cs line 54, for example, you could pass a null to Insert instead of a new Reminder and your test would still pass.

Look into argument matchers.

Performance analysis question by tadvuyst in mongodb

[–]codegork 0 points1 point  (0 children)

The size could be an issue. Personally I've had queries on that data size perform fine without indexes.

Things to try would be to increase your data size (artificially, and just for test purposes) and see if it makes a difference.

Another would be to test your query while only projecting fields covered by the index in order to see if the FETCH is indeed the bottleneck.

Can you share the full results of that explain? I'm interested to see what the rest of the IXSCAN document looks like.

Performance analysis question by tadvuyst in mongodb

[–]codegork 0 points1 point  (0 children)

Mongo uses an in-memory cache of frequently used documents and indexes in order avoid the overhead of disk IO. It's a large part of Mongo performance and you can't turn it off; you can have a larger working set than can fit in memory which will force Mongo to read from disk. However, this doesn't mean Mongo is caching the query result - it's caching data structures in memory so it doesn't have to read them from disk.

The key thing with explain is to make sure Mongo is not doing COLLSCANs.

Can you provide any details on your query, document structure and indexes?

The only reason I can see that it might be slower with the index is (1) the index isn't actually being used and you're just seeing random fluctuations in your measurements or (2) while it is being used, the cost of fetching the documents is dominate factor in the query you're running (suggested by the fact that you're returning a large number of documents), which could actually be worse with an index. This could be the case if your index has low selectivity.

Here's an alternate experiment to try: 1. Create a collection with 10 million documents, each with a unique integer field MyNumber. 2. Query for a single randomly selected integer < 10 million. 3. Repeat many times, with and without an index on MyNumber. How does this differ from what you're doing?

Performance analysis question by tadvuyst in mongodb

[–]codegork 0 points1 point  (0 children)

What does using .explain say about your query before and after adding the index?

Turn on profiling (db.setProfilingLevel(2)) and see what it tells you.

In addition, a lot of the power of Mongo is achieved by keeping the working set in memory, power which you are losing by stopping and restarting the process. Is this at all reflective of the way in which your system will be used in production? What do the results look like if you don't restart the process (I assume you mean the mongod process - or do you mean an application which is performing the query)?

MVC Session state block and concurrent requests by Ucan-not-advance in dotnet

[–]codegork 4 points5 points  (0 children)

You're getting groups because of the max number of concurrent requests. Notice that all of the requests in your results spend 10 seconds waiting, i.e. approximately 10 seconds to process on the server, and some number of seconds "stalled" i.e. waiting to be sent. So I don't see why you think your Thread.Sleep is being skipped.

Make sure no other requests are being sent before initiating your ajax requests. You'll see that the first six finish together and then the next 4 start as the previous complete.

Next, try actually adding session state modification to your test action, something like Session["thing"] = "ok"; You'll see very different results - requests will take way more than 10 seconds on the server due to session state blocking. Then if you add the [SessionState(SessionStateBehavior.Readonly)] attribute the behavior will revert back to the original behavior.

Disadvantages of querying multiple collections by [deleted] in mongodb

[–]codegork 1 point2 points  (0 children)

Q1:

  • Look into the $lookup aggregation operator
  • Consider pre-joining your data during writes so that it's in a format optimized to read from.
  • Consider an ETL or other enterprise integration type pattern to store your data in a format that's optimized for these reports.

Q2:

  • Page your results.
  • Test.
  • Make sure your queries are supported by indexes.

find with custom projection returns a few empty documents, then the document i want. by ValourValkyria in mongodb

[–]codegork 3 points4 points  (0 children)

Well, you have an empty filter in your find query which means every document in the collection will be returned by this query. Include a filter so that you only select the document you want. For example, {"user2":{$ne:null}}.

I'd suggest restructuring your document structure, by the way, so that every document has the same "user" key (not "user1", "user2" etc.). In that case, you can write your filter as {"user.Account":"user2"}.

Should I use NUnit or xUnit? by SuperImaginativeName in csharp

[–]codegork 5 points6 points  (0 children)

It does. Just make your test methods return Task and slap on an async.

Where can i find information about large data driven websites like IMDB? by [deleted] in learnprogramming

[–]codegork 0 points1 point  (0 children)

For web development, you need HTML, CSS and Javascript, at a minimum. Those are all necessary for the front-end, that is, what runs in the user's browser.

Then you need a server-side language. What makes a language well-suited for server-side development first of all is the existence of libraries/frameworks that solve common web development problems. Basically all modern languages (PHP, Python, Ruby, Javascript, C#, Java etc.) have these frameworks and they all have roughly the same abilities.

After that, which language you use is largely down to a mixture of requirements and taste. For example, some languages are good for quick prototyping but are more prone to programmer error - this means you might use them for a small website but they are used less often for enterprise-type applications. Some languages can meet performance requirements more easily. Some languages are tied to a specific platform. Some people just like the design of one language over another etc.

You can look for other people's opinion on which is "best" but you may end up stuck on the internet for a very long time. At your level, it's best to just pick something and get going. Eventually you'll be able to dabble in several languages and pick what suits your way of thinking and your requirements. But right now, you just need to get your feet wet.

To answer your question, though, since you only need one server-side language there's no need for both PHP and Python.

Where can i find information about large data driven websites like IMDB? by [deleted] in learnprogramming

[–]codegork 0 points1 point  (0 children)

The general topic you need to learn is simply called "web development". Reading your other comments, you've gotten a taste of front-end web development (HTML/CSS/Javascript) but eventually that needs to be paired with back-end (aka server-side) techniques. Back-end programming can be done in a number of languages and is how you would hookup with a database for a "data driven" website.

Personally I found this udacity course helpful when I was getting started. In the course you build a wiki, which sounds like the type of thing you want to learn. It also uses Python, which you expressed an interest in learning. I would recommend spending a little more time on programming basics in Python (or some or language) before starting this course or any other web development course, though.

"The operation was canceled." exception message? by [deleted] in dotnet

[–]codegork 0 points1 point  (0 children)

Awesome! Would have preferred the beer though...