In what cases do I use malloc vs new?

In what cases do I use malloc vs new?

I see in C++ there are multiple ways to allocate and free data and I understand that when you call malloc you should call free and when you use the new operator you should pair with delete and it is a mistake to mix the two (e.g. Calling fr

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

How to use jQuery with Angular?

How to use jQuery with Angular?

Can anyone tell me, how to use jQuery with Angular?class MyComponent { constructor() { // how to query the DOM element from here? }}I'm aware there are workarounds like manipulating the class or id of the DOM element upfront, b

Once for all, how to correctly save instance state of Fragments in back stack?

Once for all, how to correctly save instance state of Fragments in back stack?

I have found many instances of a similar question on SO but no answer unfortunately meets my requirements.I have different layouts for portrait and landscape and I am using back stack, which both prevents me from using setRetainState() and

javafx 8 compatibility issues - FXML static fields

javafx 8 compatibility issues - FXML static fields

I have designed a javafx application which works fine in jdk 7. When I try to run it in java 8 I am getting the below exceptions:javafx.fxml.LoadException: at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2617) at javafx.

Why is “import *” bad?

Why is “import *” bad?

It is recommended to not to use import * in Python. Can anyone please share the reason for that, so that I can avoid it doing next time? 1:Because it puts a lot of stuff into your namespace (might shadow some other object from previous i

What are the differences between type() and isinstance()?

What are the differences between type() and isinstance()?

What are the differences between these two code fragments?Using type():import typesif type(a) is types.DictType: do_something()if type(b) in types.StringTypes: do_something_else()Using isinstance():if isinstance(a, dict): do_someth

Why do I see a double variable initialized to some value like 21.4 as 21.399999618530273?

Why do I see a double variable initialized to some value like 21.4 as 21.399999618530273?

double r = 11.631;double theta = 21.4;In the debugger, these are shown as 11.631000000000000 and 21.399999618530273.How can I avoid this? 1:These accuracy problems are due to the internal representation of floating point numbers and ther

What is meant by Resource Acquisition is Initialization (RAII)?

What is meant by Resource Acquisition is Initialization (RAII)?

What is meant by Resource Acquisition is Initialization (RAII)? 1:It's a really terrible name for an incredibly powerful concept, and perhaps one of the number 1 things that C++ developers miss when they switch to other languages. There

Why is the Java date API (java.util.Date, .Calendar) such a mess?

Why is the Java date API (java.util.Date, .Calendar) such a mess?

As most people are painfully aware of by now, the Java API for handling calendar dates (specifically the classes java.util.Date and java.util.Calendar) are a terrible mess.Off the top of my head:Date is mutableDate represents a timestamp, n

Collision detection with complex shapes

Collision detection with complex shapes

I am wanting to make a game that has each level loaded from an image.I want to draw up the whole level in Photoshop, and then set it as the background and allow the player to walk over it.I want another invisible image to go over top which

Python: Difference between class and instance attributes

Python: Difference between class and instance attributes

Is there any meaningful distinction between:class A(object): foo = 5 # some default valuevs.class B(object): def __init__(self, foo=5): self.foo = fooIf you're creating a lot of instances, is there any difference in performan

How to compare dates in Java? [duplicate]

How to compare dates in Java? [duplicate]

This question already has an answer here: Java: how do I check if a Date is within a certain range? 10 answers How do I compare dates in between in Jav

Subscript indices must either be real positive integers or logicals, generic solution

Subscript indices must either be real positive integers or logicals, generic solution

The following error occurs quite frequently: Subscript indices must either be real positive integers or logicalsI have found many questions about this but not one with a really generic answer. Hence I would like to have the general solutio

How can I find WPF controls by name or type?

How can I find WPF controls by name or type?

I need to search a WPF control hierarchy for controls that match a given name or type. How can I do this? 1:I combined the template format used by John Myczek and Tri Q's algorithm above to create a findChild Algorithm that can be used o

Where to place and how to read configuration resource files in servlet based application?

Where to place and how to read configuration resource files in servlet based application?

In my web application I have to send email to set of predefined users like [email protected], so I wish to add that to a .properties file and access it when required. Is this a correct procedure, if so then where should I place this file? I a

Why does my ArrayList contain N copies of the last item added to the list?

Why does my ArrayList contain N copies of the last item added to the list?

I'm adding three different objects to an ArrayList, but the list contains three copies of the last object I added. For example:for (Foo f : list) { System.out.println(f.getValue());} Expected:012Actual:222What mistake have I made?Note:

Why JSF calls getters multiple times

Why JSF calls getters multiple times

Let's say I specify an outputText component like this:If I print a log message when the getter for someProperty is called and load the page, it is trivial to notice that the getter is being

Why does std::getline() skip input after a formatted extraction?

Why does std::getline() skip input after a formatted extraction?

I have the following piece of code that prompts the user for their name and state:#include #include int main(){ std::string name; std::string state; if (std::cin >> name && std::getline(std::cin, state)) {

How can I read inputs as integers?

How can I read inputs as integers?

Why does this code not input integers? Everything on the web says to use raw_input(), but I read on Stack Overflow (on a thread that did not deal with integer input) that raw_input() was renamed to input() in Python 3.x.play = Truewhile pl

How to use MySQLi inside a namespace

How to use MySQLi inside a namespace

MySQLi works fine inside a class with no namespace and outside a class. I recently started using namespace and now I have stumbled on a code much like the following: namespace Project; class ProjectClass{ public static function Project

PHP Script to populate MySQL tables

PHP Script to populate MySQL tables

Is anyone aware of a script/class (preferably in PHP) that would parse a given MySQL table's structure and then fill it with x number of rows of random test data based on the field types? I have never seen or heard of something like this an

what is the basic difference between jobconf and job?

what is the basic difference between jobconf and job?

hi i wanted to know the basic difference between jobconf and job objects,currently i am submitting my job like thisJobClient.runJob(jobconf);i saw other way of submitting jobs like thisConfiguration conf = getConf();Job job = new Job(conf,

Reloading model in laravel

Reloading model in laravel

In some of my tests, I have a user model I have created and I run some methods that need to save certain attributes. In rails, I would typically call something like user.reload which would repopulate the attributes from the database.Is ther

Serialize Map[String, Any] with spray json

Serialize Map[String, Any] with spray json

How do I serialize Map[String, Any] with spray-json? I tryval data = Map("name" -> "John", "age" -> 42)import spray.json._import DefaultJsonProtocol._data.toJsonIt says Cannot find JsonWriter or JsonFormat type class for scala.collection.im