Creating a byte array from a stream

Creating a byte array from a stream

What is the prefered method for creating a byte array from an input stream? Here is my current solution with .NET 3.5. Stream s;byte[] b;using (BinaryReader br = new BinaryReader(s)){ b = br.ReadBytes((int)s.Length);}Is it still a better

PHP: How to generate a random, unique, alphanumeric string?

PHP: How to generate a random, unique, alphanumeric string?

How would it be possible to generate a random, unique string using numbers and letters for use in a verify link? Like when you create an account on a website, and it sends you an email with a link, and you have to click that link in order t

Why not inherit from List?

Why not inherit from List?

When planning out my programs, I often start with a chain of thought like so: A football team is just a list of football players. Therefore, I should represent it with:var football_team = new List(); The ordering of this

How do I copy the contents of one stream to another?

How do I copy the contents of one stream to another?

What is the best way to copy the contents of one stream to another? Is there a standard utility method for this? 1:From .NET 4.5 on, there is the Stream.CopyToAsync methodinput.CopyToAsync(output);This will return a Task that can be cont

Set cookie and get cookie with JavaScript [duplicate]

Set cookie and get cookie with JavaScript [duplicate]

This question already has an answer here: How do I create and read a value from cookie? 14 answers I'm trying to set a cookie depending on which CSS fi

Simplest way to serve static data from outside the application server in a Java web application

Simplest way to serve static data from outside the application server in a Java web application

I have a Java web application running on Tomcat. I want to load static images that will be shown both on the Web UI and in PDF files generated by the application. Also new images will be added and saved by uploading via the Web UI.It's not

How do I remove diacritics (accents) from a string in .NET?

How do I remove diacritics (accents) from a string in .NET?

I'm trying to convert some strings that are in French Canadian and basically, I'd like to be able to take out the French accent marks in the letters while keeping the letter. (E.g. convert é to e, so crème brûlée would become creme brulee)W

Get selected element's outer HTML

Get selected element's outer HTML

I'm trying to get the HTML of a selected object with jQuery. I am aware of the .html() function; the issue is that I need the HTML including the selected object (a table row in this case, where .html() only returns the cells inside the row

Encrypt and decrypt a string in C#?

Encrypt and decrypt a string in C#?

How can I encrypt and decrypt a string in C#? 1:EDIT 2013-Oct: Although I've edited this answer over time to address shortcomings, please see jbtule's answer for a more robust, informed solution.https://stackoverflow.com/a/10366194/18847

Is an array name a pointer?

Is an array name a pointer?

Is an array's name a pointer in C?If not, what is the difference between an array's name and a pointer variable? 1:An array is an array and a pointer is a pointer, but in most cases array names are converted to pointers. A term often use

What is a NullPointerException, and how do I fix it?

What is a NullPointerException, and how do I fix it?

What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them?What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely? 1:When you dec

Reading a remote file using Java

Reading a remote file using Java

I am looking for an easy way to get files that are situated on a remote server. For this I created a local ftp server on my Windows XP, and now I am trying to give my test applet the following address:try{ uri = new URI("ftp://localhost/

Does Haskell have a splat operator like Python and Ruby?

Does Haskell have a splat operator like Python and Ruby?

In Python and Ruby (and others as well, I'm sure). you can prefix an enumerable with * ("splat") to use it as an argument list. For instance, in Python:>>> def foo(a,b): return a + b>>> foo(1,2)3>>> tup = (1,2)>>> foo(*tup)3Is there somethi

How to get elements which have no children, but may have text?

How to get elements which have no children, but may have text?

the empty selector says that: Matches all elements that have no children (including text nodes).Finds all elements that are empty - they don't have child elements or text.What i want is to get elements which has no children but may have tex

Hungarian Algorithm: How to cover 0 elements with minimum lines?

Hungarian Algorithm: How to cover 0 elements with minimum lines?

I am trying to implement the Hungarian algorithm in Java. I have an NxN cost matrix. I am following this guide step by step. So I have the costMatrix[N][N] and 2 arrays to track covered rows and covered cols - rowCover[N], rowColumn[N] (1

Text was truncated or one or more characters had no match in the target code page including the prim

Text was truncated or one or more characters had no match in the target code page including the prim

I'm trying to import a flat file into an oledb target sql server database.here's the field that's giving me trouble:here are the properties of that flat file connection, specifically the field:here's the error message: [Source - 1894297910

Vertically centering button using css

Vertically centering button using css

I am trying to make a simple input button center-align within a table cell.My markup is: XXXXXXXXX YYYYYYYY And may be viewed here:http://jsfiddle.net/tP4sD/I have done a table version showing you the la

How does atoi() function in C++ work?

How does atoi() function in C++ work?

So...I know that the atoi function in the C++ standard library is supposed to convert a string into an integer...how does it work?...(I'm trying to learn stuff and I was just wondering)...if you could show me the code from it or make your o

How to provide mock files to change event of  for unit testing

How to provide mock files to change event of for unit testing

I'm having difficulties with a unit test in which I want to verify the processing of a file, which would usually be selected in the view via .In the controller part of my AngularJS app the file is processed inside the input's change event l

Getting the type of a MemberInfo with reflection

Getting the type of a MemberInfo with reflection

I'm using reflection to load a treeview with the class structure of a project. Each of the members in a class have a custom attribute assigned to them. I don't have a problem getting the attributes for a class using MemberInfo.GetCustomAttr

How to determine main class at runtime in threaded java application?

How to determine main class at runtime in threaded java application?

I want to determine the class name where my application started, the one with the main() method, at runtime, but I'm in another thread and my stacktrace doesn't go all the way back to the original class.I've searched System properties and e

What is the optional argument in C# interpolated string for?

What is the optional argument in C# interpolated string for?

Interpolated strings is one of the new features of C# 6.0. According to MSDN, the syntax of the embedded C# expressions can contain an optional, comma-separated value, deemed as in the documentation.Unfortunately I didn't find what this fi

Cannot implicitly convert type 'System.DateTime?' to 'System.DateTime'. An expli

Cannot implicitly convert type 'System.DateTime?' to 'System.DateTime'. An expli

I am trying to convert datetime? todatetime but I get this Error: Error 7 Cannot implicitly convert type 'System.DateTime?' to 'System.DateTime'. An explicit conversion existsHere is my code:public string ConvertToPersianToShow(DateTime

How can I check if user has a webcam or not? [closed]

How can I check if user has a webcam or not? [closed]

I need to know if there's a way to know if the user has a webcam on his computer using javascript or maybe php. 1:There is a plugin: http://www.xarg.org/project/jquery-webcam-plugin/if(webcam.getCameraList().length == 0){ alert('You

Objective-C SOAP Client --Request Problem?

Objective-C SOAP Client --Request Problem?

I have generated code with WSDL2OBJC.I have big problem with request in my Objective C client:CatalogoPortBinding *binding = [[CatalogoSvc CatalogoPortBinding] initWithAddress:@"http://localhost:8080/WSServer/Catalogo_V1"]; binding.logXM