Parallel.ForEach vs Task.Run and Task.WhenAll
What are the differences between using `Parallel.ForEach` or `Task.Run()` to start a set of tasks asynchronously? Version 1: ``` List<string> strings = new List<string> { "s1", "s2", "s3" }; Parallel....
- Modified
- 19 Jan at 05:17
How can I loop through a List<T> and grab each item?
How can I loop through a List and grab each item? I want the output to look like this: ``` Console.WriteLine("amount is {0}, and type is {1}", myMoney.amount, myMoney.type); ``` Here is my code: ...
- Modified
- 25 Oct at 07:51
How to sort an ArrayList in Java
I have a class named Fruit. I am creating a list of this class and adding each fruit in the list. I want to sort this list based on the order of fruit name. ``` public class Fruit{ private Strin...
- Modified
- 9 Jan at 10:14
Is there a 'foreach' function in Python 3?
When I meet the situation I can do it in javascript, I always think if there's an `foreach` function it would be convenience. By foreach I mean the function which is described below: ``` def foreach(...
- Modified
- 27 May at 13:57
How do I build a dockerfile if the name of the dockerfile isn't Dockerfile?
I am able a build a Dockerfile like `docker build -t deepak/ruby .` But for a Dockerfile which is not named `Dockerfile` ``` # DOCKER-VERSION 0.4.8 FROM deepak/ruby MAINTAINER Deepak Kannan "deep...
- Modified
- 10 Dec at 02:13
DbEntityValidationException - How can I easily tell what caused the error?
I have a project that uses Entity Framework. While calling `SaveChanges` on my `DbContext`, I get the following exception: > System.Data.Entity.Validation.DbEntityValidationException: Validation fa...
- Modified
- 4 Apr at 19:54
What is "406-Not Acceptable Response" in HTTP?
In my Ruby on Rails application I tried to upload an image through the POSTMAN [REST](http://en.wikipedia.org/wiki/Representational_State_Transfer) client in [Base64](http://en.wikipedia.org/wiki/Base...
- Modified
- 9 May at 04:9
How do I concatenate text files in Python?
I have a list of 20 file names, like `['file1.txt', 'file2.txt', ...]`. I want to write a Python script to concatenate these files into a new file. I could open each file by `f = open(...)`, read line...
- Modified
- 12 Aug at 19:53
An expression tree may not contain a call or invocation that uses optional arguments
> An expression tree may not contain a call or invocation that uses optional arguments ``` return this.RedirectToAction<MerchantController>(x => x.Edit(merchantId)); ``` Where edit had a second, ...
- Modified
- 13 Sep at 19:39
Nesting await in Parallel.ForEach
In a metro app, I need to execute a number of WCF calls. There are a significant number of calls to be made, so I need to do them in a parallel loop. The problem is that the parallel loop exits befor...
- Modified
- 23 Nov at 19:5
How to listen for changes to a MongoDB collection?
I'm creating a sort of background job queue system with MongoDB as the data store. How can I "listen" for inserts to a MongoDB collection before spawning workers to process the job? Do I need to poll ...
- Modified
- 26 Nov at 14:40
Extract public/private key from PKCS12 file for later use in SSH-PK-Authentication
I want to extract the public and private key from my `PKCS#12` file for later use in SSH-Public-Key-Authentication. Right now, I'm generating keys via ssh-keygen which I put into `.ssh/authorized_ke...
- Modified
- 23 Apr at 15:40
How to close TCP and UDP ports via windows command line
Does somebody knows how to close a TCP or UDP socket for a single connection via windows command line? Googling about this, I saw some people asking the same thing. But the answers looked like a manu...
- Modified
- 31 Jan at 13:41
How do I get the information from a meta tag with JavaScript?
The information I need is in a meta tag. How can I access the `"content"` data of the meta tag when `property="video"`? ``` <meta property="video" content="http://video.com/video33353.mp4" /> ``` ...
- Modified
- 29 Jun at 03:19
C# XML Documentation Website Link
Is it possible to include a link to a website in the XML documentation? For example, my method's summarized as ``` ///<Summary> /// This is a math function I found HERE. ///</Summary> public void Som...
Using the HTML5 "required" attribute for a group of checkboxes?
When using the newer browsers that support HTML5 (FireFox 4 for example); and a form field has the attribute `required='required'`; and the form field is empty/blank; and the submit button is clicked;...
- Modified
- 17 Mar at 16:17
Regular expression for exact match of a string
I want to match two passwords with regular expression. For example I have two inputs "123456" and "1234567" then the result should be not match (false). And when I have entered "123456" and "123456" t...
- Modified
- 3 May at 13:44
How to return a value from a Form in C#?
I have a main form (let's call it frmHireQuote) that is a child of a main MDI form (frmMainMDI), that shows another form (frmImportContact) via ShowDialog() when a button is clicked. When the user cl...
- Modified
- 27 Sep at 21:32
Get value of c# dynamic property via string
I'd like to access the value of a `dynamic` c# property with a string: `dynamic d = new { value1 = "some", value2 = "random", value3 = "value" };` How can I get the value of d.value2 ("random") if I...
What's the best way to set a single pixel in an HTML5 canvas?
The HTML5 Canvas has no method for explicitly setting a single pixel. It might be possible to set a pixel using a very short line, but then antialising and line caps might interfere. Another way mig...
Convert JSON String To C# Object
Trying to convert a JSON string into an object in C#. Using a really simple test case: ``` JavaScriptSerializer json_serializer = new JavaScriptSerializer(); object routes_list = json_serializer.Dese...
What is the difference between `new Object()` and object literal notation?
What is the difference between this constructor-based syntax for creating an object: ``` person = new Object() ``` ...and this literal syntax: ``` person = { property1 : "Hello" }; ``` It ap...
- Modified
- 29 Dec at 15:11
try/catch + using, right syntax
Which one: ``` using (var myObject = new MyClass()) { try { // something here... } catch(Exception ex) { // Handle exception } } ``` OR ``` try { using (var myObje...
- Modified
- 4 Jan at 03:53
CSS content generation before or after 'input' elements
In Firefox 3 and Google Chrome 8.0 the following works as expected: ``` <style type="text/css"> span:before { content: 'span: '; } </style> <span>Test</span> <!-- produces: "span: Test" --> ``` ...
How do I copy a hash in Ruby?
I'll admit that I'm a bit of a ruby newbie (writing rake scripts, now). In most languages, copy constructors are easy to find. Half an hour of searching didn't find it in ruby. I want to create a copy...
- Modified
- 13 Oct at 18:10