devx-admin

Understandng toExactInt method in java.lang.Math package

java.lang.Math has numerous methods and our interest here is toIntExact() method.Consider the following example public class MathExact{   public static void main(String args[])   {      MathExact mathExact = new MathExact();      mathExact.proceed();   }      private void proceed()   {      long l = 100000000;      int i = (int) l;       System.out.println(“i: ” + i);            System.out.println(“Math.toIntExact(“+l+”);: ” + Math.toIntExact(l));   }} /* Expected output: [[email protected]]# java MathExacti: 100000000Math.toIntExact(100000000);: 100000000 */

Get the First Day of the Current Month

To get the first date of the current month, you could a query similar to the following: SELECT CONVERT(VARCHAR(25),DATEADD(DAY,-(DAY(GETDATE())) +1, GETDATE()), 105) Day1;

Adjusting Views to Reduce Visibility of Data in MySQL

Let us consider a table representing employee data with a few columns, and, of course, their salary details as well. It is not wise to expose this table to all querying entities since there is sensitive data that makes sharing the contents problematic. In real time, there are VIEWS that

Find error log location

It is quite easy to find the error log location through a quick query such as : SELECT SERVERPROPERTY(‘ErrorLogFileName’) AS ‘Error log file location’   This shows where your Error log file is stored

DBCC SHRINKDATABASE

DBCC SHRINKDATABASE The command shrinks the size of the data and log files in a database. Here is a small example: DBCC SHRINKDATABASE (Database_Name, 10);  –This allows for 10 percent free space in the database.

How to Trigger a Synchronous GET Request

For triggering a synchronous GET request we can rely on HTTP Client API as follows: HttpClient client = HttpClient.newHttpClient();HttpRequest request = HttpRequest.newBuilder() .uri(URI.create(“https://reqres.in/api/users/2”)) .build();HttpResponse response = client.send(request, BodyHandlers.ofString());

Check for finite numbers in Python

Use the math module???s isfinite method to determine if a value is finite or not.  If it is not a number, the function returns false.  See below for an example:math.isfinite(10) returns True

How to detect Python version at runtime

At times, we want to run our code only if the version of Python engine is above a certain version. See below for sample code. Import sysversion = sys.version

No more posts to show