Tuesday, 1 May 2018

c++ - The address of my object in a vector changes

I filled a vector with A objects, then stored these objects address in a multimap [1], but the print message shows that the reference to the object stored in the vector changed [2]. Do you see why? and how avoid any changes.



//[1]
vector vec;
multimap mymultimap;

for (const auto &a : A) {
double val = a.value();

vec.push_back(a);
mymultimap.insert(std::pair( &vel.back(), val));

// displaying addresses while storing them
cout<<"test1: "<<&vec.back()<
}

//[2]
// displaying addresses after storing them

for(auto &i : vec)
cout << "test2: " << &i <


Results:



test1: 0x7f6a13ab4000  
test1: 0x7f6a140137c8
test2 :0x7f6a14013000
test2 :0x7f6a140137c8

c++ - Recommended usage of std::unique_ptr

What are recommended uses of a std::unique_ptr as to specifically where, when, and how is it is best used?



I discovered:



About unique_ptr performances




I already know:




  1. std::unique_ptr was developed in C++11 as a replacement for std::auto_ptr

  2. That a std::unique_ptr has no reference counting and "owns" object it points to

  3. There is no copy/assign with a std::unique_ptr

  4. When I need a unique pointer, std::unique_ptr is the go to structure



What I would like to know:





  1. Is using a std::unique_ptr ever preferable (other than uniqueness) to something
    else? What do I gain in this situation?

  2. If so, under what circumstances and when?

  3. Given the need for move semantics, would this make a std::unique_ptr less favorable
    overall?

  4. If a std::shared_ptr would suffice for dynamic memory management in nearly every
    situation, why does having at my disposal a std::unique_ptr matter (again, other
    than uniqueness)?

java - Using Regex to generate Strings rather than match them



I am writing a Java utility which helps me to generate loads of data for performance testing. It would be really cool to be able to specify a regex for Strings so that my generator spits out things which match this. Is there something out there already baked which I can use to do this? Or is there a library which gets me most of the way there?



Thanks


Answer



Edit:



As mentioned in the comments, there is a library available at Google Code to acheive this:
http://code.google.com/p/xeger




See also https://github.com/mifmif/Generex as suggested by Mifmif



Original message:



Firstly, with a complex enough regexp, i believe this can be impossible. But you should be able to put something together for simple regexps.



If you take a look at the source code of the class java.util.regex.Pattern, you'll see that it uses an internal representation of Node instances. Each of the different pattern components have their own implementation of a Node subclass. These Nodes are organised into a tree.



By producing a visitor that traverses this tree, you should be able to call an overloaded generator method or some kind of Builder that cobbles something together.



c# - The name 'Model' does not exist in the current context ASP.NET MVC5




I am coding a PlugIn to NopCommerce 3.2, and in the views I get the error mentioned above, but also for 'Layout' and 'Html'. I have copied the same Web.Config that works in another plugin. I have also added the same references as used in the working Plugin. When compiling the plugin works, but I don't have any intellisense and can't trust that VisualStudio marks errors correctly. I am using VS2013 Professional Update 1.



Here is the Web.Config file:




























validateRequest="false"

pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">






























EDIT: Sorry if you find this question not researched, but I assure you I have spent hours to try to find the solution (including those questions I have found here in stackoverflow that are similar and pointing out web.config as the problem which is the reason I have included that file in my question) but can't find it.


Answer



This error was probably caused by Resharper. We are a team of three developers using GIT. One of us installed Resharper, and this probably caused the error for the other two of us. When we installed Resharper trial it suddenly worked again. Unfortunately it isn't working when uninstalling Resharper again...


If statement structure in PHP

Greater than or equal to is >= sign, not =>


Update:
You are right. It's small but hard to find mistake.
It took me to split whole line into pieces to see where the problem is:


if
(
$varp
=>
80000
)

So, it says parse error on line 5 and I had to doublecheck this operator.
Of course, at first I separated the problem line from the rest of the code to be certain.

mysql - PHP isn't processing some form fields

Answer


Answer





I recently created a PHP/MySQL comment system, and it was working until a few hours ago (no changes at all in the code). When I tell the submit form code to echo the query, it shows that the area for commenttext and date is missing. I don't see why. Here's my code:




mysql_connect("localhost","commentUser","password");
mysql_select_db("comments");
$name = mysql_real_escape_string($_POST['name']);
$postID = mysql_real_escape_string($_POST['postId']);
if(!is_numeric($postID))
exit();

$email = mysql_real_escape_string($_POST['email']);
$comment = strip_tags(mysql_real_escape_string($_POST['comment']), '');
$date = mysql_real_escape_string($_POST['date']);

if($email == '' || $comment = '' || $date = '')
exit();

$query = "INSERT INTO comments (PostID,Name,Email,Text,Date) VALUES($postID, '$name', '$email', '$comment', '$date')";
mysql_query($query) or die(mysql_error());
mysql_close();


echo "

window.location = \"snippet.php?id=$postID\";

";


Answer



You are assigning the empty string to $comment and $date with =




if($email == '' || $comment = '' || $date = '')
exit();

// Should use `==` for all three:
if($email == '' || $comment == '' || $date == '')
exit();

mysql - Grant **all** privileges on database




I've created database, for example 'mydb'.



CREATE DATABASE mydb CHARACTER SET utf8 COLLATE utf8_bin;
CREATE USER 'myuser'@'%' IDENTIFIED BY PASSWORD '*HASH';
GRANT ALL ON mydb.* TO 'myuser'@'%';
GRANT ALL ON mydb TO 'myuser'@'%';
GRANT CREATE ON mydb TO 'myuser'@'%';
FLUSH PRIVILEGES;



Now i can login to database from everywhere, but can't create tables.



How to grant all privileges on that database and (in the future) tables. I can't create tables in 'mydb' database. I always get:



CREATE TABLE t (c CHAR(20) CHARACTER SET utf8 COLLATE utf8_bin);
ERROR 1142 (42000): CREATE command denied to user 'myuser'@'...' for table 't'

Answer



GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'%' WITH GRANT OPTION;



This is how I create my "Super User" privileges (although I would normally specify a host).





While this answer can solve the problem of access, WITH GRANT OPTION creates a MySQL user that can edit the permissions of other users.




The GRANT OPTION privilege enables you to give to other users or remove from other users those privileges that you yourself possess.





For security reasons, you should not use this type of user account for any process that the public will have access to (i.e. a website). It is recommended that you create a user with only database privileges for that kind of use.


casting - Why wasn&#39;t Tobey Maguire in The Amazing Spider-Man? - Movies &amp; TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...