Browsing 7239 questions and answers with Jon Skeet

Java How to get the difference between currentMillis and a timestamp in the past in seconds

Lets say i have long currentMillis and long oldMillis. The difference between the two timestamps is very tiny and always less than 1 second. If i want to know the difference...
Jon Skeet
people
quotationmark

It sounds like you just need to convert the results into double before the division: // This will work double differenceMillis = currentMillis - oldMillis; double differenceSeconds = differenceMillis / 1000; // This will *not*... more 6/11/2014 4:59:32 PM

people

How do I create a method in UserManager?

How do I create a method in UserManager like: public UserManager<ApplicationUser> UserManager { get; private set; } public ActionResult SomeAction() { ...
Jon Skeet
people
quotationmark

If you want to return an empty result, you can use the EmptyResult class: public ActionResult SomeAction() { UserManager.MyVoid(); return new EmptyResult(); } more 6/11/2014 4:23:14 PM

people

Java memory allocation difference between DXX and XX

I'm automating a mule stack. The client wants his java binary to run with -DXX:MaxPermSize=4096M -XX:MaxPermSize=4096m Can someone explain the difference between DXX and XX...
Jon Skeet
people
quotationmark

-D[...] is just a flag to set a "system property". Unless anything looks at that system property, it will have no effect at all. For example: System.out.println(System.getProperty("XX:MaxPermSize")); ... will print out "4096M" in your... more 6/11/2014 12:17:50 PM

people

Java8: How to get the internal Type of java.util.Optional class?

I have an object of type: Optional<String> and I would like to know at runtime what is the generic type of Optional - meaning 'String'. I've tried: obj.getClass() but...
Jon Skeet
people
quotationmark

There's no such thing as an object of type Optional<String>. Type erasure means that there's just Optional at execution time. If you have a field or parameter of type Optional<String>, that information can be retrieved at... more 6/11/2014 9:15:27 AM

people

Ping.SendAsync() always successful, even if client is not pingable in cmd

I try to ping some IP addresses in C# using Ping.SendAsync() method. I have a treeView with 5 IP addresses and use the SendAsync() method for each node. Here you can see: private...
Jon Skeet
people
quotationmark

Every time you get any PingCompleted event, you're updating all the nodes in your tree the same way. Instead, you should only update the node corresponding to the IP address that the particular PingCompletedEventArgs corresponds with. You... more 6/11/2014 9:10:55 AM

people

BigInteger.toByteArray() returns purposeful leading zeros?

I'm transforming bigints into binary, radix16 and radix64 encoding and seeing mysterious msb zero paddings. Is this a biginteger problem that I can workaround by stripping zero...
Jon Skeet
people
quotationmark

Yes, this is the documented behaviour: The byte array will be in big-endian byte-order: the most significant byte is in the zeroth element. The array will contain the minimum number of bytes required to represent this BigInteger,... more 6/11/2014 8:59:30 AM

people

Why some methods of ObservableCollection and List might be unavailable?

I work on Windows Phone 8 app. Some methods of ObservableCollection and List are unavailable at several pages (not at all pages). Such methods as OrderBy and ElementAt. So, I...
Jon Skeet
people
quotationmark

Those aren't methods on ObservableCollection or List themselves. They're extension methods provided by the System.Linq.Enumerable class. You probably just need an added using directive in your source code to make them available: using... more 6/11/2014 8:50:24 AM

people

C# Math.Round Up

I've got a question. I have a decimal and I want to round this at 2 decimals, not at the ordinary way but 0.2013559322033898305084745763 desired result: 0.21 How can I do...
Jon Skeet
people
quotationmark

It sounds like you want a version of Math.Ceiling, but which takes a number of decimal places. You could just multiply, use Math.Ceiling, then divide again: public static double CeilingWithPlaces(double input, int places) { double... more 6/11/2014 8:43:01 AM

people

Select all nodes with attribute using xpath

I am trying to select all nodes using root.SelectNodes() with XPath. For reference, see msdn-documentation. In the following document explained, you can also search for nodes...
Jon Skeet
people
quotationmark

I suspect the reason it's failing has nothing to do with the attribute part - it's failing to find the elements at all, as you've asked for just Compile elements, whereas there are only actually Compile elements in the namespace with the... more 6/11/2014 8:39:40 AM

people

XNode.DeepEquals unexpectedly returns false

Using XNode.DeepEquals() to compare xml elements, it unexpectedly returns false on two xml documents that I think should be equivalent. Example var xmlFromString =...
Jon Skeet
people
quotationmark

I've worked out what the difference is, but not why it's different. In the first form, you have an xmlns attribute. In the second form, you don't - not in terms of what Attributes() returns. If you explicitly construct an XAttribute,... more 6/11/2014 7:15:57 AM

people