How to format a JavaScript date

For custom-delimited date formats, you have to pull out the date (or time) components from a DateTimeFormat object (which is part of the ECMAScript Internationalization API), and then manually create a string with the delimiters you want. To do this, you can use DateTimeFormat#formatToParts. You could destructure the array, but that is not ideal, as …

Read more

Reverse a string in Java

You can use this: Or, for versions earlier than JDK 1.5, use java.util.StringBuffer instead of StringBuilder — they have the same API. Thanks commentators for pointing out that StringBuilder is preferred nowadays when there is no concurrency concern.

strdup() – what does it do in C?

Exactly what it sounds like, assuming you’re used to the abbreviated way in which C and UNIX assigns words, it duplicates strings 🙂 Keeping in mind it’s actually not part of the ISO C standard itself(a) (it’s a POSIX thing), it’s effectively doing the same as the following code: In other words: It tries to allocate enough memory …

Read more

Convert list to array in Java [duplicate]

Either: or: Note that this works only for arrays of reference types. For arrays of primitive types, use the traditional way: Update: It is recommended now to use list.toArray(new Foo[0]);, not list.toArray(new Foo[list.size()]);. From JetBrains Intellij Idea inspection: There are two styles to convert a collection to an array: either using a pre-sized array (like …

Read more

How do I install pip on macOS or OS X?

This question’s answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions. I spent most of the day yesterday searching for a clear answer for installing pip (package manager for Python). I can’t find a good solution. How do I install it?

What do ++ and *+ mean?

++ From What is double plus in regular expressions? That’s a Possessive Quantifier. It basically means that if the regex engine fails matching later, it will not go back and try to undo the matches it made here. In most cases, it allows the engine to fail much faster, and can give you some control …

Read more