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,

Rails 4: how to use $(document).ready() with turbo-links

Rails 4: how to use $(document).ready() with turbo-links

I ran into an issue in my Rails 4 app while trying to organize JS files "the rails way". They were previously scattered across different views. I organized them into separate files and compile them with the assets pipeline. However, I just

Reading a resource file from within jar

Reading a resource file from within jar

I would like to read a resource from within my jar like so:File file;file = new File(getClass().getResource("/file.txt").toURI());BufferredReader reader = new BufferedReader(new FileReader(file));//Read the fileand it works fine when runnin

What is the difference between visibility:hidden and display:none?

What is the difference between visibility:hidden and display:none?

The CSS rules visibility:hidden and display:none both result in the element not being visible. Are these synonyms? 1:display:none means that the tag in question will not appear on the page at all (although you can still interact with it

How to merge two arrays in JavaScript and de-duplicate items

How to merge two arrays in JavaScript and de-duplicate items

I have two JavaScript arrays:var array1 = ["Vijendra","Singh"];var array2 = ["Singh", "Shakya"];I want the output to be:var array3 = ["Vijendra","Singh","Shakya"];The output array should have repeated words removed.How do I merge two arrays

Manipulating an Access database from Java without ODBC

Manipulating an Access database from Java without ODBC

I want to manipulate a Microsoft Access database (.accdb or .mdb file) from my Java project. I don't want to use the JDBC-ODBC Bridge and the Access ODBC driver from Microsoft because:the JDBC-ODBC Bridge has been removed from Java SE 8 and

Cannot start LocalDB

Cannot start LocalDB

Cannot start LocalDB instance, I have installed and re-installed over and over. Keep getting this error : Start of LocalDB instance "v11.0" failed because of the following error: Error occurred during LocalDB instance startup: SQL Server

What is the default for AngularJS directive scope?

What is the default for AngularJS directive scope?

What is the default scope value of an AngularJS directive? Of course, it is not isolated scope. It is true or false. I can't find any documentation on what it is. 1: "Note, by default, directives do not create new scope -- i.e., the def

Python 2.5 dictionary 2 key sort

Python 2.5 dictionary 2 key sort

I have a dictionary of 200,000 items (the keys are strings and the values are integers).What is the best/most pythonic way to print the items sorted by descending value then ascending key (i.e. a 2 key sort)? a={ 'keyC':1, 'keyB':2, 'keyA':

Stem plot in matplotlib?

Stem plot in matplotlib?

I want to plot(x, sin(x)) but instead of a line from (xi,yi) to (x_i+1,y_i+1) I want a vertical line to each point from (xi,0) to (xi,yi) as sometimes interpolation between the points makes no sense (e.g. quantized data) (and it looks much

Visual Studio: Configuration Manager missing

Visual Studio: Configuration Manager missing

I'm using Microsoft Visual Studio Team System 2008 Team Suite.The "Configuration Manager" menu item is missing for me. I've assigned a keyboard shortcut to the Configuration Manager, but it doesn't have any effect (actually, it produces a "

Ruby on Rails 4 - simple_form multiple select input

Ruby on Rails 4 - simple_form multiple select input

I have a simple_form input field that looks like this:When I leave multiple: true off, the form submits the chosen value for the parameter :particular_users and I can see the value when debugging using "raise params.inspect". However when I

Convert array-of-hashes to a hash-of-hashes, indexed by an attribute of the hashes

Convert array-of-hashes to a hash-of-hashes, indexed by an attribute of the hashes

I've got an array of hashes representing objects as a response to an API call. I need to pull data from some of the hashes, and one particular key serves as an id for the hash object. I would like to convert the array into a hash with the k

Failing to run jar file from command line: “no main manifest attribute”

Failing to run jar file from command line: “no main manifest attribute”

I am trying to run a jar file from the console:java -jar ScrumTimeCaptureMaintenence.jarAnd am getting the error: Can't execute jar- file: “no main manifest attribute”As you can see I do in fact have a main file and it runs fine from eclip

How to call a controller method from a button in rails 4

How to call a controller method from a button in rails 4

So I feel really stupid right now, but I can't seem to find an answer.So I have a method which needs to be called EXACTLY once, and since this is only the experimental phase, I decided that a simple button should suffice. However, I can't s

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

Is there a way to STOP not TERMINATE instances using auto-scaling in AWS?

Is there a way to STOP not TERMINATE instances using auto-scaling in AWS?

I am looking at using AWS auto-scaling to scale my infrastructure up and down based on various performance metrics (CPU, etc.). I understand how to set this up; however, I don't like that instances are terminated rather than stopped when it

Where are Java final local variables stored?

Where are Java final local variables stored?

Take the following example:public void init() { final Environment env = new Environment(); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { env.close(); } });}Firstly, where is env

is it possible to add a comment to a diff file (unified)?

is it possible to add a comment to a diff file (unified)?

I wonder if it's possible to add a certain amount of unparsed content to a diff file (unified) that is ignored as a comment.One good use of this would be having git diffs augmented with important information such as from which branch is th

Android Studio using existing android sdk

Android Studio using existing android sdk

I already have the latest android sdk with all platforms/sources/etc downloaded.How can i tell Android Studio to use an existing android sdk without moving it to android-studio\sdk\? 1:Follow this:Open up your project in Android Studio.G

Verbose Output From rake assets:precompile

Verbose Output From rake assets:precompile

I've just started using the asset_sync gem and my assets seem to be being compiled out of order, with Sass files unabled to access variables defined in other Sass files. What would really help me narrow down the issue is being able to see e

jquery $(this).id return Undefined

jquery $(this).id return Undefined

I have two asp radio buttons on a page that are placed in a updatepanel. I wrote a click event for them with jQuery like this:$(document).ready(function () { $(".inputs").click(function () { alert($(this).id); });});But it ret

How do I mount a filesystem using Python?

How do I mount a filesystem using Python?

I'm sure this is a easy question, my Google-fu is obviously failing me.How do I mount a filesystem using Python, the equivalent of running the shell command mount ...?Obviously I can use os.system to run the shell command, but surely there

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

in pycharm, how to go back to last location

in pycharm, how to go back to last location

i've tried these answers, but nothing happened:Keyboard shortcut for Jump to Previous View Location (Navigate back/forward) in IntelliJ Ideafor example:i'm navigating to a function body,put the cursor on a function call,click F12 ("go to de