Angular path with hyphen character not allowed - angularjs

When I use the following:
$location.path('/product/ninja-game'); //No error in console but the path isn't changed
The path is not changed but it works when I use following:
$location.path('/product/ninja_game');
Is there anything specific to hyphen/dash character in angularjs path. I couldn't find anything specific in the docs.
Code:
$scope.buildProductDetails = function(product) {
var tempTitle = product.title.toLowerCase();
tempTitle = tempTitle.replace(/adobe/g, "").trim();
tempTitle = tempTitle.replace(/\s+/g, '-'); //replacing space with hyphen
console.log(tempTitle);
$location.path('/product/' + tempTitle);
}

Hyphen/dash should not be a problem
Probably the problem is in the variable tempTitle.
Hardcode the path like $location.path('/product/ninja-game'); and check just to see whether the problem in the variable tempTitle.

Related

Windows Defender API to scan a directory for malwares

Using Windows Defender API , I'm trying to do a scan for malwares on a folder.
Following The documentation I wrote the code:
MPRESOURCE_INFO ResourceInfo = { 0 };
MPSCAN_RESOURCES ScanResource = { 0 };
PMPRESOURCE_INFO ResourceInfoArray = NULL;
...
ResourceInfo.Scheme = L"dir";
ResourceInfo.Path = L"C:\\temp";
ResourceInfo.Class = 0;
// ResourceInfoArray was Allocated before
*ResourceInfoArray = ResourceInfo;
ScanResource.dwResourceCount = 1;
ScanResource.pResourceList = ResourceInfoArray;
// Opened hMpManager before using MpScanStart
hRetval = MpScanStart(hMpManager, MPSCAN_TYPE_RESOURCE, 0, &ScanResource, NULL, &ScanHnadle);
From which I get an error message: An unexpected problem occurred. Install any available updates, and then try to start the program again. For information on installing updates, see Help and Support.
However If I change the ResourceInfo definition to:
ResourceInfo.Scheme = L"file";
ResourceInfo.Path = L"C:\\temp\\MyFile.exe";
ResourceInfo.Class = 0;
It works great, detecting the file in the right way.
On the bottom line - the code works for files, but doesn't work for directories.
Does anyone know what am I doing wrong with the directory search?
Analyzing event logs created by MpCmdRun.exe I found out that it uses the scheme "folder" instead of "dir". That change made my code working.
ResourceInfo.Scheme = L"folder";
Folder paths do not have to end with backslash, but drives require it: (F:\).

Need to check whether any extension is present before query string

I have written the code to check the query string
Logic::if query string is "?" should remove all the characters from the query string and print the vailid URL.
char str[] = "http://john.org/test.mp4?iufjdlwle";
char *pch;
pch = strtok(str,"?");
printf("%s\n",pch);
Output::
bash-3.2$ ./querystring
http://john.com/test.mp4
But i have to check one more case
Need to get the URL only if there is any extensions present before query string?
if No extensions are present before the query string,need to skip.
I have tried this way,
continuation of the code
char *final;
final = pch+(strlen(pch)-3);
printf("%s\n",final);
if(strcasecmp(p,"mp4"))
printf("falure case\n");
else
printf("Success case\n");
It will work for .mp4 extension alone.
Incase if i'm getting *.mpeg or *.m3u8 or *.flv as an extensions,it will fail.
Can someone guide me how to solve this problem and make it working?
A query string is what starts after a question mark ?, fine.
You should try to define what an extension is. For me, it is what can happen after a dot (.) in the last component of the url, where the components are delimited with slashes (/)
So you should do:
first remove the possible query string including the initial ?
then locate the last /
then locate the last . that occurs after the last /
If you find one, it is the starting point of the extension.
So assuming pch contains the url without any query string, you can do:
char * ix = strrchr(pch, '/');
if (ix == NULL) {
// an URL without / is rather weird, better report and abort
...
}
ix = strrchr(ix, '.');
if (ix == NULL) {
// no extension here: ignore the url
...
}
else {
// found an URL containing an extension: process it
// ix+1 points to the extension
...
}

Why am I getting ng-repeat dupe error when I use a for loop instead of if statement?

The code in this Plunker works as it should (just the first 3 links do something). But as the list started to grow I realized I needed a for loop. So within the switch function I transformed this:
if(obj == "SP") {
$scope.discipline ='Link2'
return $scope.files = spFiles;
}
else if(obj == "LSM"){
$scope.discipline = "Link3"
return $scope.files = lsmFiles;
}
else if(obj == "AR"){
$scope.discipline = "Link1"
return $scope.files = arFiles;
}
Into this:
for(i=0;i<disciplines.length;i++){
if(obj == disciplines[i].initial){
return $scope.files = disciplines[i].array;
}
}
The disciplines array is located at the top of the script.js file.
Problem is, now suddenly I am getting a dupes error when I click on one of the links. I haven't a clue what is duplicating. I read the documentation for this error and added the track by $index to the ng-repeat located on the bottom of index.html. Take a look at this Plunker to see what it does now. Certainly there is a simple explanation for this. I've never encountered this though.
The only other answer I could find on here that seems to pertain to my question is this one, but, the object that is being used by the ng-repeat isn't a JSON object I'm pretty sure:
spFiles.push({
floor:floors[c].name, initial:floors[c].initial, status:spFloorStatus[i]
});
Plus, it was working before I created the for loop causing the trouble.
I apologize if anything is unclear. Please, if you need me to clarify anything just let me know, I tried to be as thorough and as least confusing as possible.
That's because disciplines[i].array return just string, not your variable, named arFiles.
You can initialize these variables as:
var tempFiles={};
and then add:
tempFiles.arFiles={
floor:floors[c].name, initial:floors[c].initial, status:arFloorStatus[i]
};
and get :
return $scope.files = tempFiles[disciplines[i].array];

In Scala, read a file where specified path includes multiple environment variables

For a file path name such as
val path = "$HOME/projects/$P1/myFile.txt"
is there a simpler way to resolve the path and read myFile.txt than this,
import java.io.File
val resolvedPath = path.split(File.separator).map{ s =>
if (s.startsWith("$")) sys.env(s.drop(1))
else s }.
mkString(File.separator)
val res = io.Source.fromFile(resolvedPath).getLines
The way you have seems good to me, but if you are so inclined or need to do something quickly, you could use Process to get the return of executing a bash command:
import scala.sys.process._
val cleanedPath = Seq("bash", "-c", "echo " + path).!!.trim
You can even use this idea to read the file if you want:
val text = Seq("echo", "-c", "cat " + path).!!
One difference between these and your code is that your code will throw an exception if an environment variable is missing, while bash returns an empty string for that variable. If you wish to mimic that, you could use sys.env.get(s.tail).getOrElse("") instead of sys.env(s.drop(1)) or use the dictionary val myEnv = sys.env.withDefaultValue("").
See System.getenv(). You'll be able to find the variables and replace them with the value to resolve your path.

AS3: Error #1065: Variable is not defined

Using getDefinitionByName I am consistently getting the error saying it is not defined (as the title says). The particular code I am using is
var tileID:String = String(getDefinitionByName("evt.target.data."+mapData[i][j]))
mapData is already populated by a character in each position. The plan is that I can use the value of whatever mapData is as the variable name for the conversion of the single character to the full linkage name of a tile. These properties come from another external .txt file that is setup for variables (this is the external file the code line links to).
The variables in the external file look something like &N=exampleTile.
So when it comes to setting tileID it should end up being exampleTile. (Assuming mapData[i][j] = "N").
But it doesn't. I have read around at other solutions saying that the file may not have loaded or anything, but I can't make sense of or apply any of those fixes.
As Florian points out, getDefinitionByName is specifically for getting a Class reference. Something like "flash.net.URLLoader" would give you a reference to the URLLoader class for example. It's not used for getting regular variables by their names (so "evt.target.data.N" wouldn't return anything even if "N" was a property of data).
It sounds like your evt.target.data is a long string along the lines of "A=tileA&B=tileB&C=tileC". If so, you need to parse that string out to separate variables first. You should be able to use URLVariables with that data format (flash.net.URLVariables), then you can read the parsed variables using the [ ] array access operator: urlVariablesObject["variableName"]. So you might do something like this:
import flash.events.Event;
import flash.net.URLVariables;
import flash.net.URLLoader;
import flash.net.URLRequest;
var loader:URLLoader = new URLLoader();
var parsedData:URLVariables;
var mapData:Array = [["A", "B", "C"], ["D", "E", "F"]];
loader.addEventListener(Event.COMPLETE, externalFileLoaded);
loader.load(new URLRequest("externalFile.txt"));
// externalFile.txt contains "A=tileA&B=tileB&C=tileC&D=tileD&E=tileE&F=tileF".
function externalFileLoaded(evt:Event):void {
parsedData = new URLVariables(evt.target.data);
var tileID:String = readMap(0, 1);
trace(tileID); // "tileB".
}
function readMap(i:uint, j:uint):String {
var mapValue:String = mapData[i] [j];
var tileID:String = parsedData[mapValue];
return tileID;
}
That doesn't make any sense. getDefinitionByName is used to retrieve a Class instance of a certain type - the Class named like the string passed. And the definition will always start with "evt.target.data.".
Did you ever debugged your way through it?
function any_handler(i:int, j:int):void {
const suffix:String = mapData[i][j],
qualifiedName:String = "evt.target.data." + suffix;
// this is wrong
const titleID:String = String(getDefinitionByName(qualifiedName));
}
You really should take a look in the debugger in order to know the value of the string you are creating.

Resources