Friday, 1 September 2017

geolocation - How do I get the current GPS location programmatically in Android?

I need to get my current location using GPS programmatically.
How can i achieve it?

What is a native implementation in Java?




If we look at the Java Object class then we can find some of the methods like:



public native int hashCode()
protected native Object clone()


What are these natives and how do these methods work?


Answer



These methods are either Intrinsic or written outside Java in "native" code, that is, specific to the given machine.




The ones you mention are Intrinsic and part of the JDK but you can also write native methods yourself using the Java Native Interface (JNI). This would normally use C to write the methods, but a lot of other languages, such as python allow you to write methods this way fairly easily. Code is written this way either for performance, or because it needs to access platform specific infrastructure which cannot be done in plain java.



In the case of hashcode(), this is implemented by the JVM. This is because often the hashcode will be related to something only the JVM knows. On early JVMs this was related to the object's location in memory - on other JVMs the Object may move in memory, and so a more complicated (but still very fast) scheme may be used.


the dark knight rises - What is the reason for the color scheming of Nolan's Batman franchise? - Movies & TV



Throughout the three Batman films, there has been one running theme in common. Each movie has its own color scheme.





  • Batman Begins - Brown & Black

  • The Dark Knight - Blue & Red

  • Dark Knight Rises - White & Black



enter image description here



What is Nolan's reason for this? Is there a meaning behind the colors that directly link back into the major theme of the films? Or are these colors a way to represent the overall situation throughout the movie?


Answer




I see these colors/movie titles as the day in the life of a bat, beginning at sunset (orange) and ending at sunrise (white/bight) with a dark night in between (blue). Also plays on the titles; BEGINS, NIGHT and sunRISE. That is another nice conclusion to the saga.


html - How to Implement DOM Data Binding in JavaScript

Please treat this question as strictly educational. I'm still interested in hearing new answers and ideas to implement this



tl;dr



How would I implement bi-directional data-binding with JavaScript?




Data Binding to the DOM



By data binding to the DOM I mean for example, having a JavaScript object a with a property b. Then having an DOM element (for example), when the DOM element changes, a changes and vice versa (that is, I mean bidirectional data binding).



Here is a diagram from AngularJS on what this looks like:



two way data binding



So basically I have JavaScript similar to:




var a = {b:3};


Then an input (or other form) element like:






I'd like the input's value to be a.b's value (for example), and when the input text changes, I'd like a.b to change too. When a.b changes in JavaScript, the input changes.




The Question



What are some basic techniques to accomplish this in plain JavaScript?



In specific, I'd like a good answer to refer to:




  • How would binding work for objects?

  • How listening to change in the form might work?

  • Is it possible in a simple way to only have the HTML modified on the template level? I'd like to not keep track of the binding in the HTML document itself but only in JavaScript (with DOM events, and JavaScript keeping reference to the DOM elements used).




What have I tried?



I'm a big fan of Mustache so I tried using it for templating. However, I ran into issues when trying to perform the data binding itself since Mustache processes HTML as a string so after I get its result I have no reference to where the objects in my viewmodel are. The only workaround I could think for this was modifying the HTML string (or created DOM tree) itself with attributes. I don't mind using a different templating engine.



Basically, I got a strong feeling that I was complicating the issue at hand and there is a simple solution.



Note: Please do not provide answers that use external libraries, especially ones that are thousands of lines of code. I've used (and like!) AngularJS and KnockoutJS. I really don't want answers in the form 'use framework x'. Optimally, I'd like a future reader who doesn't know how to use many frameworks to grasp how to implement bi-directional data-binding herself. I do not expect a complete answer, but one that gets the idea across.

c# - StyleCop and FxCop rules exclude each other



I'm using StyleCop and FxCop tools to improve my code but I came to a place where there are two rules, one in StyleCop and one in FxCop that exclude each other. If I fix my code to match the rule from StyleCop then FxCop validation fails and vice versa.




First rule is SA1200 from StyleCop which says that all using directives must be placed inside of the namespace.




All using directives must be placed inside of the namespace.




So I have done something like this



namespace MyNamespace

{
using System;

...
}


It was ok for StyleCop, no more warnings. Now I run FxCop validation and it tells me that CA1014 is violated:





Mark 'MyApp.dll' with CLSCompliant(true) because it exposes externally visible types.




To resolve this I should do something like this:



[ClsCompliant(true)]
namespace MyNamespace
{
...
}



but now I cannot build my project because ClsCompliant attribute is not recognized (because it's from System namespace which I include inside of the MyNamespace). So if I move using System; directive outside of MyNamespace declaration. This will make my code compile but again it will break the rule from StyleCop.



Is there any way to deal with this problem except for disabling one of the rules in StyleCop or FxCop? And if that's not possible which of the rules should I disable? Which is less important?


Answer



Use full attribute name:



[System.CLSCompliant(true)]
namespace MyNamespace

{
...
}


BTW: if you want to mark your whole assembly as CLSCompliant, put



[assembly: System.CLSCompliant(true)]



in Properties/AssemblyInfo.cs file


It's that possible in JavaScript

Help, how can I make this to "Correct" true without change the condition.
Just changing the Variable value.
In JavaScript




         Let Variable;
\*
If(Variable == 1 && Variable == 2 && Variable == 3)
Console.log("Correct");
else
Console.log("Incorrect");

*\

PHP -MySQL:No connection could be made







I tried to connect mysql database.but am getting the following error.





Warning: mysql_connect(): [2002] No connection could be made because the target machine actively (trying to connect via tcp://localhost:3306) in test.php on line 5



Warning: mysql_connect(): No connection could be made because the target machine actively refused it. in test.php on line 5 Warning: mysql_close() expects parameter 1 to be resource, boolean given in test.php on line 15




test.php:



$link = mysql_connect(localhost, dbuser, dbpass);
if (!$link) {

die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & 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...