devxlogo

upload

Monitor Log space in SQL Server quickly

You can use the following command to monitor all your databases’ log file’s free space DBCC SQLPERF (‘LOGSPACE’)

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

Return multiple values from a function in python

Python can return multiple values at a time. See below for a simple example. def multipleValueFunc():     z = 11     b = 22    return z, b  j,k  = multipleValueFunc () print(j, k) 

Reverse a string in Python

Its pretty ease to reverse a string in Python. ???Devx Jan???[::-1]  gives ???naJ xveD???

Understandng Objects.deepEquals

We understand how equals() method works. There is a more elaborate method deepEquals() which compares in depth details during comparison.Basic usage is described below. Let us explore more using these as examples. import java.util.Objects; public class DeepEquals{   public static void main(String args[])   {      DeepEquals deepEquals = new DeepEquals();      deepEquals.proceed();   }      private void proceed()   {      System.out.println(“Objects.deepEquals(1,1): ” + Objects.deepEquals(1,1));      System.out.println(“Objects.deepEquals(1,2): ” + Objects.deepEquals(1,2));      System.out.println(“Objects.deepEquals(“abc”,”abc”): ” + Objects.deepEquals(“abc”,”abc”));      System.out.println(“Objects.deepEquals(“aa”,”ab”): ” + Objects.deepEquals(“aa”,”ab”));   }} /* Expected output: [root@mypc]# java DeepEqualsGetting handle of runtime ConsoleGot handle of runtime ConsoleYou can now use runtimeConsole object to perform actions of your choice on java.io.Console */

Getting console of the current runtime environment.

The Runtime class provides mechanism to get the console of the current runtime environment. Using this, we can perform needed actions on the console. import java.io.*; public class SystemConsole{   public static void main(String args[])   {      SystemConsole systemConsole = new SystemConsole();      systemConsole.proceed();   }      private void proceed()   {      System.out.println(“Getting handle of runtime Console”);      Console runtimeConsole = System.console();      System.out.println(“Got handle of runtime Console”);      System.out.println(“You can now use runtimeConsole object to perform actions of your choice on java.io.Console”);   }} /* Expected output: [root@mypc]# java SystemConsoleObjects.deepEquals(1,1): trueObjects.deepEquals(1,2): falseObjects.deepEquals(“abc”,”abc”): trueObjects.deepEquals(“aa”,”ab”): false */

Converting Base 10 numbers to Binary numbers

Programming needs vary. You may have a requirement to convert a Base 10 value to binary as part of a complex logic. Java has easier mechanism to achieve the same. public class Base10ToBinary{   public static void main(String args[])   {      Base10ToBinary base10ToBinary = new Base10ToBinary();      base10ToBinary.proceed();   }      private void proceed()   {      int num = 10;       String binaryNum = Integer.toString(num, 2);         System.out.println(“Binary value of ” + num + ” : ” + binaryNum);    }} /* Expected output: [root@mypc]# java Base10ToBinaryBinary value of 10 : 1010 */