Sunday, September 1, 2019

angularjs - Can ngRoute support non-configured links?



I am trying to fix up an existing implementation, however I can't do it all at once. Is there anyway I can get ngRoute, even if it's a hack, to support old links that expect to make a direct request?



Here's what I mean, we have three links in this weird example TODO App:



Home
New Task
Complete Task



"Home" and "New Task" should use the angular ngRoute, making it nice and snappy. My other links, such as "Complete" would need to work like they always have, the full round trip.



Initially I configured ngRoute with this:



angular.module('TodoApp', [
// Angular modules
'ngRoute'
// Custom modules


// 3rd Party Modules
]).config(['$locationProvider', '$routeProvider',
function config($locationProvider, $routeProvider) {
$routeProvider.when('/', {
templateUrl: 'Templates/index.html',
controller: 'TodoController'
})
.when('/Home/AddItem', {
templateUrl: 'Templates/AddItem.html',

controller: 'AddItemController'
});
// Otherwise, continue to the link like normal.
$locationProvider.html5Mode(true);
}
]);


However that won't work, so far, here's the full list of options that I've tried:




Don't configure otherwise



This only gave me a blank page as ngRoute is blocking the browser from making an http request.



Hide/Show view div



I've tried configuring the router to hide or show the divs based on what url is being rendered, this almost works. I can go to a bookmarked page and it will render, but I can't navigate through the website via clicking an link. I get the same blank page because ngRoute blocked it again.



Configure otherwise




I tried a "NoView" controller, doesn't work. Also found that if I put this code in



redirectTo: function() {
return undefined;
}


I can get it to at least render without errors, but again ngRoute blocks the browser from making an http request.



Disable ngRoute




I tried detecting when the configured path is being used, only then would I enable angular. While there are errors in the console at least it works for bookmarked links. Again though, once it becomes enabled ngRoute will start blocking links while clicking around the site. You'll start to see blank pages instead.



I would try the alternative angular-ui-route, but I don't know if it supports this case. Routing seems to be all or nothing. Are there any hacks to get around this or another framework that supports this case?



There's a lot of links so I would like to leave them alone and only enable new features until we can go back and fix up the old ones.



Final Approach



Adding for those who are curious, I ended up merging one of my attempts with Horst Jahns answer. Basically it looks like this:




var angularConfigs = [
// Set all configs here, routing will be conditionally added later.
// Angular modules

// Custom modules

// 3rd Party Modules
];


var routeSettings = [{
entry: '/',
template: 'Templates/index.html',
controller: 'TodoController'
}, {
entry: '/Home/AddItem',
template: 'Templates/AddItem.html',
controller: 'AddItemController'
}
];


// Check current url matches routes being registered. If so enable routing.
var enableRotues = false;
for (var i = 0; i < routeSettings.length; i++) {
if (routeSettings[i].entry === window.location.pathname) {
enableRotues = true;
break;
}
}


if (enableRotues) {
// Attach the module to existing configurations.
angularConfigs.push('ngRoute');
var todoApp = angular.module('TodoApp', angularConfigs);

todoApp.config([
'$locationProvider', '$routeProvider',
function config($locationProvider, $routeProvider) {
var provider = $routeProvider;


// Go through each setting and configure the route provider.
for (var i = 0; i < routeSettings.length; i++) {
var route = routeSettings[i];

provider = provider.when(route.entry,
{
templateUrl: route.template,
controller: route.controller
});
}


// This enables links without hashes, gracefully degrades.
$locationProvider.html5Mode(true);
}
]);

// This directive will disable routing on all links NOT
// marked with 'data-routing-enabled="true"'.
todoApp.directive('a', function() {
return {

restrict: 'E',
link: function(scope, element, attrs) {
if (attrs.routingEnabled) {
// Utilize the ngRoute framework.
} else {
// Disable ngRoute so pages continue to load like normal.
element.bind('click', function(event) {
if (!scope.enabled) {
event.preventDefault();
window.location.href = attrs.href;

}
});
}
}
};
});
} else {
// In this case we still want angular to properly be stood
// up and register controllers in my case for backward
// compatibility.

angular.module('TodoApp', angularConfigs);
}

Answer



You could write a directive and set it on all the links, which are not configured.



Angular



app.directive('nonConfig', function() {
return {

restrict: 'A',
link: function(scope, element, attrs) {
element.bind('click', function(event) {
if(!scope.enabled) {
event.preventDefault();
window.location.href = attrs.href;
}
});
}
};

});


HTML



test

php - The second argument to copy() function cannot be a directory



Anyone know why this:



$title = trim($_POST['title']);
$description = trim($_POST['description']);


// Array of allowed image file formats
$allowedExtensions = array('jpeg', 'jpg', 'jfif', 'png', 'gif', 'bmp');

foreach ($_FILES as $file) {
if ($file['tmp_name'] > '') {
if (!in_array(end(explode(".",
strtolower($file['name']))),
$allowedExtensions)) {
echo '
Invalid file type.
';
}

}
}

if (strlen($title) < 3)
echo '
Too short title
';
else if (strlen($description) > 70)
echo '
Too long desccription.
';

else {
move_uploaded_file($_FILES['userfile']['tmp_name'], 'c:\wamp\www\uploads\images/');

}


Gives:



Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory in C:\wamp\www\upload.php on line 41


Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\wamp\tmp\php1AB.tmp' to 'c:\wamp\www\uploads\images/' in C:\wamp\www\upload.php on line 41

Answer



It's because you're moving a file and it thinks you're trying to rename that file to the second parameter (in this case a director).




it should be:



move_uploaded_file($_FILES['userfile']['tmp_name'], 'c:/wamp/www/uploads/images/'.$file['name']);

mysql - mysql_connect in php 5.6 +

I was using PHP 5.4 in Godaddy Hosting. I have one PHP script which was working fine in it. Now I have changed Hosting and New Hosting company Provide PHP 5.6. I do not PHP coding. I am getting error in my script as below



Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home4/z4g9f1v6/public_html/mydomain.com/folder/config.php on line 7



My Configure file is like below


$mysql_hostname = "localhost";
$mysql_user = "dbuser";
$mysql_password = "dbpass";
$mysql_database = "dbname";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database");
mysql_select_db($mysql_database, $bd) or die("Could not select database");

and I am using it in my Search.php like below


include("config.php");
if($_SERVER["REQUEST_METHOD"] == "POST")
{
mysql_query('SET character_set_results=utf8');
mysql_query('SET names=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_connection=utf8');
mysql_query('SET character_set_results=utf8');
mysql_query('SET collation_connection=utf8_general_ci');
$q=$_POST['q'];
$q=mysql_escape_string($q);
$q_fix=str_replace(" ","%",$q); // Space replacing with %
$sql=mysql_query("SELECT qu_text FROM quotes WHERE qu_text LIKE '%$q%'");
}while($row=mysql_fetch_array($sql)){$title=$row['qu_text'];

Please help me. How can I solve the issue ?


Thanks

Saturday, August 31, 2019

PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:apache2triadhtdocsimagedisplay.php on line 28

hi i am getting an error during my execution of the code : PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:\apache2triad\htdocs\imagedisplay.php on line 28





$dir= "C:\apache2triad\htdocs\phppgadmin\images\phpimages";

$file_display= array('jpg', 'jpeg', 'png', 'gif');

if(file_exists($dir)== false)
{
echo "directory x not found";

}
else
{
$dir_content= scandir($dir);

foreach($dir_content as $file)
{
$file_type = strtolower(end(explode('.', $file)));

// echo "$file
";


if($file !=='.' && $file !=='..')
{
//echo "$file
";
echo "', $file, '";
}
}
}
?>



please help

plot explanation - Maximus fighting the masked champion in the arena with tigers - Movies & TV



When Maximus is knocked to the ground he lands a shot through his opponent's foot with an axe. His opponent then seems to be spitting blood (hard to tell due to the helmet) and then falls over dead.



Why did he die?


Answer



This is from the script. I couldn't find a video. The blood probably comes from the blow to the head. Tigris was pretty injured from this hit but was probably trying to hold back any sign of his being hurt that bad until the axe went into his foot and he couldn't stand the pain so the blood that was in his mouth from the hit to the head came out at that time.



Maximus finally manages to land a stunning blow to his opponent’s head causing Tigris to drop his axe. Maximus switches his sword to his other hand and stands ready to administer the killing blow. Suddenly a fourth tiger jumps out of the last door and leaps on Maximus and just as quickly, Maximus twists and turns his sword arm, impaling the tiger. He is thrown to the ground by the weight of the beast all the while stabbing and eventually killing the big cat. The crowd cheers.




Tigris seeing an advantage moves closer. Maximus, pinned under the weight of the tiger, reaches out and grabs Tigris lost axe. The axe has a spike on one end and in one movement; Maximus brings the spike down and into the top of Tigris foot. Tigris bends over from the pain, blood pouring from the mouth of his mask. Maximus jumps to his feet and kicks Tigris to the ground. Maximus standing over the fallen Tigris lifts the other man’s face cover and raised the axe. He looks to Commodus for direction. The crowd yells.


sql - How to combine rows in Amazon Redshift

Redshift provides a function LISTAGG() for what you need



SELECT id, name, LISTAGG(Color,' ') AS Colors
FROM yourtable
GROUP BY id, name




For each group in a query, the LISTAGG aggregate function orders the
rows for that group according to the ORDER BY expression, then
concatenates the values into a single string.
http://docs.aws.amazon.com/redshift/latest/dg/r_LISTAGG.html




SELECT id, name
, LISTAGG(Color,' ') WITHIN GROUP (ORDER BY name) AS Colors
FROM yourtable
GROUP BY id, name

Easiest way to convert int to string in C++




What is the easiest way to convert from int to equivalent string in C++. I am aware of two methods. Is there any easier way?



(1)



int a = 10;
char *intStr = itoa(a);
string str = string(intStr);



(2)



int a = 10;
stringstream ss;
ss << a;
string str = ss.str();

Answer



C++11 introduces std::stoi (and variants for each numeric type) and std::to_string, the counterparts of the C atoi and itoa but expressed in term of std::string.




#include  

std::string s = std::to_string(42);


is therefore the shortest way I can think of. You can even omit naming the type, using the auto keyword:



auto s = std::to_string(42);



Note: see [string.conversions] (21.5 in n3242)


hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...