Invalid argument supplied for foreach()

Invalid argument supplied for foreach()

It often happens to me to handle data that can be either an array or a null variable and to feed some foreach with these data.$values = get_values();foreach ($values as $value){ ...}When you feed a foreach with data that are not an array,

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

Non-static variable cannot be referenced from a static context

Non-static variable cannot be referenced from a static context

I've written this test code:class MyProgram{ int count = 0; public static void main(String[] args) { System.out.println(count); }}But it gives the following error:Main.java:6: error: non-static variable count cannot be re

AngularJS: Set the model to be = {} again doesn't clear out input type='url'

AngularJS: Set the model to be = {} again doesn't clear out input type='url'

I have a fiddler setup, when i click a reset button it should clear out the input controls, this seems to work but not when the input type='url'Here is the fiddlerIs there an issue or something that I am not understanding.When I set $scope.

mysqli_free_result necessary?

mysqli_free_result necessary?

I was looking through my code and read that it was recommened to use mysqli_free_result when your result object is not needed anymore. But after seeing that each query is outputed to the $result variable repeatedly throughout the script, I

Static keyword in function parameter

Static keyword in function parameter

I've just found this function definition in some embedded code:float round_float_to_4(static float inputval);I'm familiar with other uses for static (global variables, functions and local variables), but this is the first time I see it as s

Creating tuples from two vectors

Creating tuples from two vectors

If I have two vectors of the same length A and B how can I easily turn these two vectors into a single tuple vector i. e. c((5,7),(7,13))? 1:Others have mentioned lists. I see other possibilities:cbind(A, B) # makes a column-major 2x2-

Type.GetProperties() missing in Xamarin PCL

Type.GetProperties() missing in Xamarin PCL

In Xamarin PCL, I'm trying to get the System.Reflection.PropertyInfo of a class I've written so that I can access its properties by their string name to get/set, and Type.GetTypeInfo() is missing, as well as Type.GetProperties. But System.R

Date constructor: numeric arguments vs. string argument giving different dates in some cases

Date constructor: numeric arguments vs. string argument giving different dates in some cases

First of all, I think timezone probably has something to do with this. I'm in EST/EDT. Also, I'm testing this on chromium 17 / linux.Now, let's say I create two dates like this:// December 5dateFromNumbers = new Date(2020, 11, 5);dateFromSt

In Maven, how can I exclude all transitive dependencies from a particular dependency?

In Maven, how can I exclude all transitive dependencies from a particular dependency?

I want to exclude all transitive dependencies from one dependency. In some places I've seen it suggested to use a wildcard for that myParentPackage myParentProject 1.00.000 * * When I do that I get a

Why Java does not allow null while declaring primitive data types [duplicate]

Why Java does not allow null while declaring primitive data types [duplicate]

This question already has an answer here: Null for primitive data types 9 answers This is in continuation to my previous question and accroding to answ

Is it necessary to use template parameters to refer to same class inside definition?

Is it necessary to use template parameters to refer to same class inside definition?

Is this necessary: template class A{ T*point; A someFunction(){} //instead of returning just "A", not "A" }Will someFunction implicitly return the A of the same type as the class being defined? Because outside the class, you can only r

Register a Stream “completion” hook

Register a Stream “completion” hook

Using the Java 8 Stream API, I would like to register a "completion hook", along the lines of:Stream stream = Stream.of("a", "b", "c");// additional filters / mappings that I don't controlstream.onComplete((Completion c) -> { // This is

Switch Python Version for Vim & Syntastic

Switch Python Version for Vim & Syntastic

Is it possible to change the python version used by syntastic for syntax checking?As the Issue https://github.com/scrooloose/syntastic/issues/385 indicates I could use virtual-env. But is it also possible just with syntastic or vim command

How does one declare the type of an Android preference?

How does one declare the type of an Android preference?

I have a preferences.xml that looks like this: When I do sp.getString("sample", "3.0"), it works fine and returns a string, but it shouldn't be a string, it should be a float. Running sp.getFloat("sample", 3.0f) throws a ClassCastException

Array declaration and initialization in Java. Arrays behave differently, when the position of their

Array declaration and initialization in Java. Arrays behave differently, when the position of their

The following is the obvious and usual array declaration and initialization in Java.int r[], s[]; //A very similar case behaves differently, when the position of [] is changed in the declaration statement like as shown below.int []p,

How to determine whether a string is valid JSON?

How to determine whether a string is valid JSON?

Does anyone know of a robust (and bullet proof) is_JSON function snippet for PHP? I (obviously) have a situation where I need to know if a string is JSON or not.Hmm, perhaps run it through a JSONLint request/response, but that seems a bit o

Add non-nullable columns to an existing table in SQL server?

Add non-nullable columns to an existing table in SQL server?

I already have a table which consists of data. I need to alter the table to add two new columns which are not null. How can I do that without losing any existing data?Here's what I tried (via right-clicking the table and selecting Design):A

sqlite convert 'dd.MM.yyyy' formated String to date

sqlite convert 'dd.MM.yyyy' formated String to date

i have a sqlite database on my android, whith a datetime column, that contains a date with the Format dd.MM.yyyy.It's not my Database, I'm niot able to change the Dateformat.I want to compare the date in the database with a String, which is

Automatically check Java files for coding standard compliance

Automatically check Java files for coding standard compliance

I'm working in Java development. I have recently come into a situation where I have to comply to coding standards: member and method ordering, naming conventions, modifier sequence. I am thinking about methods to either automate checking fo

Key-Value Coding (KVC) with Array/Dictionary in Swift

Key-Value Coding (KVC) with Array/Dictionary in Swift

Is it possible to key-value code (KVC) with native Swift data structures such as Array and Dictionary? Key-Value coding is still available for NSFoundation structures within Swift, just like in Objective C. For example, this is valid:var ns

C# help required to Create Facebook AppSecret_Proof HMACSHA256

C# help required to Create Facebook AppSecret_Proof HMACSHA256

Facebook requires that I create a appsecret_proof: https://developers.facebook.com/docs/graph-api/securing-requestsAnd I have done this using the following code:public string FaceBookSecret(string content, string key){ var encoding

jQuery 1.5 AJAX call fails with “invalid label” for JSON requests

jQuery 1.5 AJAX call fails with “invalid label” for JSON requests

I've just upgraded from version 1.4 to version 1.5 of jQuery, and now my AJAX calls always fail with the "invalid label" error.An example request is:jQuery.ajax({ async: false , dataType: "json" , error: function (xhr, status, erro

Android xml merge layout error on inflate

Android xml merge layout error on inflate

I have a CustomView class and I want to use xml layout for it. So, my class extends RelativeLayout, inflates xml layout and tries to attach it to self. public class CustomView extends RelativeLayout{ public CustomView (Context context) {

The HTTP request is unauthorized with client authentication scheme 'Ntlm'

The HTTP request is unauthorized with client authentication scheme 'Ntlm'

While calling a web service I get the following error: The HTTP request is unauthorized with client authentication scheme 'NTLM'. The authentication header received from the server was 'NTLM'. The HTTP request is unauthorized with client a