Given any value of type Int or Long to render a human readable string:
fun Long.humanReadable(): String {
if (this <= 0) return "0"
val units = arrayOf("B", "KB", "MB", "GB", "TB", "EB")
val digitGroups = (Mat...
A common use case for extension methods is to improve an existing API. Here are examples of adding exist, notExists and deleteRecursively to the Java 7+ Path class:
fun Path.exists(): Boolean = Files.exists(this)
fun Path.notExists(): Boolean = !this.exists()
fun Path.deleteRecursively(): Bool...
With this declaration:
fun Temporal.toIsoString(): String = DateTimeFormatter.ISO_INSTANT.format(this)
You can now simply:
val dateAsString = someInstant.toIsoString()
Let's say you have an object like this:
var myObject = {
name: 'Peter'
}
Later in your code, you try to access myObject.name and you get George instead of Peter. You start wondering who changed it and where exactly it was changed. There is a way to place a debugger (or something else) on e...
"Use DIRECT PATH method for inserting new rows".
The APPEND hint instructs the engine to use direct path load. This means that the engine will not use a conventional insert using memory structures and standard locks, but will write directly to the tablespace the data. Always creates new b...
Often people try to index some content and then find it. If they cannot see the expected result, they try to troubleshoot the whole end-to-end process. The better way is to see whether the content actually indexed in the expected fields. This way it splits the problem into two: indexing and searchin...
You can implement the swipe-to-dismiss and drag-and-drop features with the RecyclerView without using 3rd party libraries.
Just use the ItemTouchHelper class included in the RecyclerView support library.
Instantiate the ItemTouchHelper with the SimpleCallback callback and depending on which functi...
using System.Net;
using System.IO;
...
string requestUrl = "https://www.example.com/submit.html";
HttpWebRequest request = HttpWebRequest.CreateHttp(requestUrl);
request.Method = "POST";
// Optionally, set properties of the HttpWebRequest, such as:
request.AutomaticD...
using System.Net;
using System.IO;
...
string requestUrl = "https://www.example.com/page.html";
HttpWebRequest request = HttpWebRequest.CreateHttp(requestUrl);
// Optionally, set properties of the HttpWebRequest, such as:
request.AutomaticDecompression = DecompressionMethods.GZ...
When creating Random instances with the same seed, the same numbers will be generated.
int seed = 5;
for (int i = 0; i < 2; i++)
{
Console.WriteLine("Random instance " + i);
Random rnd = new Random(seed);
for (int j = 0; j < 5; j++)
{
Console.Write(rnd.Next(...
Two Random class created at the same time will have the same seed value.
Using System.Guid.NewGuid().GetHashCode() can get a different seed even in the same time.
Random rnd1 = new Random();
Random rnd2 = new Random();
Console.WriteLine("First 5 random number in rnd1");
for (int i = 0...
There are three visibility types that you can apply to methods (class/object functions) and properties (class/object variables) within a class, which provide access control for the method or property to which they are applied.
You can read extensively about these in the PHP Documentation for OOP Vi...
This query selects all employees not on the Supervisors table.
SELECT *
FROM Employees
WHERE EmployeeID not in (SELECT EmployeeID
FROM Supervisors)
The same results can be achieved using a LEFT JOIN.
SELECT *
FROM Employees AS e
LEFT JOIN Supervisors AS s ON s.E...