Author: Bob

  • Getting smallest character in a string using Python

    If you have a string and you want to get the smallest character(lowest ASCII value), you can use min().

    str = "abcde"
    print("Min character: " + min(str))
    
    #prints: Min character: a
  • How to get current date and time in MySQL datetime format using PHP

    To get current date and time in PHP, you can use the date function which returns the current timestamp according to the defined format.

    echo date("Y-m-d H:i:s");

    This prints current date and time in MySQL datetime format.

  • PHP NULL-Safe Operator

    PHP 8 introduced a new operator, called “Null-Safe Operator”.

    It allows for checking if a method or variable returns null, but doesn’t throw an error.

    Can be used in method chaining by returning as soon as it finds a null returned value from any of the methods.

    class A{
      public function b(){
        return 'Hello World';
        }
    }

    Instead of:

    $returnValue = null;
    
    $a = new A;
    
    if ($a !== null){
      
      if($a->b() !== null){
        $returnValue = 'Not null';
        }
     }

    Can be written as:

    $a = new A;
    
    $returnValue = $a?->b() ? 'Not Null' : null;
  • What are code comments?

    Code comments are a way to describe what a line, or several lines of code are doing.

    Comments are not excuted by the complier.

    It’s generally a good practice to add comments to your code, it will help you understand it in the future. And will aid your colleagues in understanding what the logic does.

    They can also be used to tell the compiler not to excute some lines.

    In most programming languages, comments can be written by adding “double slashes” then the comment.

    You can also do multi-line comments by surrounding your comment with “/*”.

    This is an example comment:

    //prints "Hello World" to the console.
    cout << "Hello World"; 
    
    /* cin >> name;
       cout << name; */
  • Using CSS media queries to create responsive design

    It’s crusial now to make websites and web applications fit different screen sizes, especially mobile screens.

    To achieve that, one way is to use CSS media queries.

    Here’s an example:

    @media only screen and (max-width: 600px) {
      .logo{
          width: 50px;
          height: auto;
      }
    }

  • How to add clickable telephone or email prompt to your HTML

    Adding email sending prompt, or phone call prompt in HTML is easy.

    For telephone:

    <a href=”Tel:0000000000″> Call us </a>

    For email:

    <a href=”Mailto:contact@info-bits.io”> Email us </a>
    

  • How to have universal password in Laravel

    In Laravel, you can create “master password” which can be used with original one.

    It’s usually used for testing and development purposes.

    This can be done using the following package:

    https://github.com/imanghafoori1/laravel-MasterPass

  • Generate Database Schema ERD in Mysql Workbench

    You can generate a database schema PDF file using Mysql Workbench by following these steps:

    1. Go to Database menu option.
    2. Select Reverse Engineer.
    3. Follow the wizard steps .
    4. Click on File => Export => Export as pdf.

  • Buttons Types in HTML

    Buttons can be of different types in html, for example if you have a form, the submit button would be of type=’submit‘. There are also two other types which are: ‘button‘ and ‘reset‘.

    The ‘button‘ type does not do anything by default but can be listened to using javascript. The ‘reset‘ type resets all form controls to their default values.

    These are some examples:

    <button type="button">Click Me!</button>
    <button type="submit">Submit</button>
    <button type="reset">Reset</button>

  • PHP Null Coalescing Operator

    In php 7 you can check if a variable contains null value and assign accordingly:

    $a = $x ?? 'default';