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

How to enable CORS in AngularJs

How to enable CORS in AngularJs

I have created a demo using JavaScript for Flickr photo search API. Now I am converting it to the AngularJs.I have searched on internet and found below configuration. Configuration:myApp.config(function($httpProvider) { $httpProvider.defau

Regex match entire words only

Regex match entire words only

I have a regex expression that I'm using to find all the words in a given block of content, case insensitive, that are contained in a glossary stored in a database. Here's my pattern:/($word)/iThe problem is, if I use /(Foo)/i then words li

Find unique rows in numpy.array

Find unique rows in numpy.array

I need to find unique rows in a numpy.array.For example:>>> a # I havearray([[1, 1, 1, 0, 0, 0], [0, 1, 1, 1, 0, 0], [0, 1, 1, 1, 0, 0], [1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 1, 0]])>>> new_a # I want to get toarray([[1,

Select rows which are not present in other table

Select rows which are not present in other table

I've got two postgresql tables: table name column names----------- ------------------------login_log ip | etc.ip_location ip | location | hostname | etc.I want to get every IP address from login_log which doesn't have a row

Map two lists into a dictionary in Python

Map two lists into a dictionary in Python

Imagine that you have:keys = ('name', 'age', 'food')values = ('Monty', 42, 'spam')What is the simplest way to produce the following dictionary ?a_dict = {'name' : 'Monty', 'age' : 42, 'food' : 'spam'}This code works, but I'm not reall

How to force NSLocalizedString to use a specific language

How to force NSLocalizedString to use a specific language

On iPhone NSLocalizedString returns the string in the language of the iPhone.Is it possible to force NSLocalizedString to use a specific language to have the appin a different language than the device ? 1:NSLocalizedString() (and variant

Regex Pattern to Match, Excluding when… / Except between

Regex Pattern to Match, Excluding when… / Except between

--Edit-- The current answers have some useful ideas but I want something more complete that I can 100% understand and reuse; that's why I set a bounty. Also ideas that work everywhere are better for me than not standard syntax like \KThis q

Why use apparently meaningless do-while and if-else statements in macros?

Why use apparently meaningless do-while and if-else statements in macros?

In many C/C++ macros I'm seeing the code of the macro wrapped in what seems like a meaningless do while loop. Here are examples.#define FOO(X) do { f(X); g(X); } while (0)#define FOO(X) if (1) { f(X); g(X); } elseI can't see what the do wh

What is `type_info::before` useful for?

What is `type_info::before` useful for?

According to cplusplus.com, the std::type_info::before() function... Returns true if the type precedes the type of rhs in the collation order. The collation order is just an internal order kept by a particular implementation and is not ne

How can I echo commands in a tcsh script?

How can I echo commands in a tcsh script?

Yes. I know I shouldn't be using it for scripting. Yes. It is rubbish. I am indeed a fool.Nevertheless.I'd like to see the commands the script is executing, for debugging purposes. I think you get this effect with set -x or set -v in bash s

What are advantages of using a one-to-one table relationship? (MySQL)

What are advantages of using a one-to-one table relationship? (MySQL)

What are advantages of using a one-to-one table relationship as opposed to simply storing all the data in one table? I understand and make use of one-to-many, many-to-one, and many-to-many all the time, but implementing a one-to-one relatio

How can I ensure no code uses an API?

How can I ensure no code uses an API?

I want to ban use of iostreams in a code base I have (for various reasons). Is there a way I can inspect symbol files or force the compiler to emit an error when that API is used? 1:A simple approach is provide a dummy iostream implement

How can I call a Perl package I define in the same file?

How can I call a Perl package I define in the same file?

I need to define some modules and use them all in the same file. No, I can't change the requirement.I would like to do something like the following:{ package FooObj; sub new { ... } sub add_data { ... }}{ package BarObj; use

resume uploads using HTTP?

resume uploads using HTTP?

Is it possible to resume interrupted uploads using HTTP Post? I am working on a project that uploads several files to a HTTP server. Thanks. 1:Assuming you have control at a low enough level on both client and server sides of this projec

How do you set a default pager for the MySQL client?

How do you set a default pager for the MySQL client?

I know you can set a pager in mysql (the client program) using e.g. \P less. But how would one configure mysql so that your pager of choice is activated whenever you start using the client? 1:To force this without having to pass paramete

How to use “setup.cfg” instead of setup.py with Python 2.7

How to use “setup.cfg” instead of setup.py with Python 2.7

It seemed to me, that instead of the whole plethora of named keyword-arguments forthe distutils.core.setup function, one can use a setup.cfg file in the same directoryas the setup.py file and all these keywords will be read from the setup.c

Right way to use the @NonNull annotation in Android Studio

Right way to use the @NonNull annotation in Android Studio

I'd like to use the @NonNull annotation in Android, but I can't figure out just the right way to do it.I propose you this example:public void doStuff(@NonNull String s){ //do work with s... }So when i call doStuff(null) the IDE will

DialogFragment in Android with theme

DialogFragment in Android with theme

I'm building my first app in android. I've made a dialogFragment, but it doesn't look nice enough.For having a style and a theme I used this setStyle(DialogFragment.STYLE_NORMAL,0). What I want is that the edge of the fragment to be black l

What's the deal with [ComVisible] default and public classes COM exposure?

What's the deal with [ComVisible] default and public classes COM exposure?

MSDN has this article about [ComVisible] attribute. I don't quite get what happens when one sets [ComVisible(true)].MSDN says The default is true, which indicates that the managed type is visible to COM. This attribute is not needed to mak

Backbone model.save() is sending PUT instead of POST

Backbone model.save() is sending PUT instead of POST

I call save using this:console.log(this.model.isNew());console.log(this.model);this.model.save({}, { success: function (model, response, options) { console.log(response); }, error: function (model, xhr, options) { con

Installing a local package on Meteor

Installing a local package on Meteor

I'm trying to run a local package on Meteor.I've got a correct package.js, have a smart.json, and it's inside my /packages directory in my Meteor project. The smart.json at my project looks like this:{ "packages": { "router": {},

Memory efficient strings in Haskell

Memory efficient strings in Haskell

The commonly recommended Haskell string types seem to be ByteString or Text. I often work with a very large number of short (English word sized) strings, and typically need to store them in a lookup table such as Data.Map. In many cases I f

How to choose an integer linear programming solver?

How to choose an integer linear programming solver?

I am newbie for integer linear programming.I plan to use a integer linear programming solver to solve my combinatorial optimization problem.I am more familiar with C++/object oriented programming on an IDE.Now I am using NetBeans with Cygwi

Where should I put the “ttf” files in an Android project?

Where should I put the “ttf” files in an Android project?

I'm trying to use fonts in my project using Typeface. I copied the "font.ttf" into a folder named "fonts" inside "assets" folder. But eclipse do not allow to compile it. It shows an error on fonts folder. What should I do?The error I get is