How to install .deb file with dependency in Ubuntu

Run Below command

sudo apt install ./dbeaver-ce_4.3.0_amd64.deb

then run this to fix dependency

apt-get -f install

curl:(51) : SSL certificate subject name does not match target host name

Add below two lines.

<?php

error_reporting(E_ALL);
ini_set('display_errors', true);


$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://XXX.XXX.XX.XXX/bankservices/process",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_SSL_VERIFYPEER => 0,
  CURLOPT_SSL_VERIFYHOST => FALSE,

  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache",
    "content-type: application/xml",
    "postman-token: b7d1eae0-ec7d-a9ae-fb6a-19abf9ef6d59"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

Check if an array contains any element of another array in JavaScript

arr1 = ['AuditOfficer','ExecutiveOperations','BranchManager','Employee','HO','Vendor','account'];
arr2 = ['Vendor','account']; 


let found = arr1.some(r=> arr2.indexOf(r) >= 0);

console.log(found);

Publishing your android app





//  generate private key

keytool -genkey -v -keystore vishututkey-release-key.keystore -alias vishututkey -keyalg RSA -keysize 2048 -validity 10001

// To sign the unsigned APK

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore vishututkey-release-key.keystore vishutut-release.apk vishututapp



Check two Dates is Equal in Javascript

function isEqual(startDate, endDate) {
    return endDate.valueOf() == startDate.valueOf();
}

var date1 = new Date('2015-01-28');
var date2 = new Date('2015-01-30');


if(isEqual(date1, date2)){
   console.log('Equal');
}else {
  console.log('not equal')
}

How To Modifiy the responce data in DataTable ( dataSrc)

ajax: {
                url: this._listingURL,
                method: 'POST',
                data: {
                    fromDate: "",
                    toDate: "",
                },
                dataSrc: function (json) {
                    let json = json;
                    json.recordsTotal = json.data.length;
                    json.recordsFiltered = json.data.length;
                    json.draw = json.data.draw;
                    var return_data = new Array();
                    for (var i = 0; i < json.data.length; i++) {
                        return_data.push({
                            'id': json.data[i].id,
                            'srNo': json.data[i].srNo,
                            'branchId': json.data[i].branchId,
                            'branchName': json.data[i].branchName,
                            'centerId': json.data[i].centerId,
                            'centerName': json.data[i].centerName,
                            'noOfLoans': json.data[i].noOfLoans,
                            'staus': json.data[i].staus
                        })
                    }
                    return return_data;
                }
            },

Call JavaScript Function at particular interval

<html>
    <head>
    </head>
    <body>
<div id="div1">

</div>
    </body>


    <script type="text/javascript">

$(document).ready(function () {
   var interval = setInterval(callAjax, 10);
   
   function callAjax() {
$.ajax({url: "http://www.delveaxis.com/", success: function (result) {
// $("#div1").html(result);
   }});
   }

});

    </script>
</html>

Good Practice for DOM manipulation




var $input= $( '#input' ); // reference to dom element

$input.css( 'color' , 'red' );

$input.attr( 'value' , 'costam' );

$input.show();


The best method ( Chaining ) 

var $input = $('#input'); // reference to dom element

$input.css('color', 'red').attr('value', 'costam').show();

Extend current objects with jQuery

Note : its good practice to extend objects instead of recreate them


// Navigation component scripts
var bobcat = bobcat || {};

bobcat.components = $.extend(bobcat.components, {

    "navigation": (function() {
        this._init = function() {
            // some initial functions
        }

        return {
            init: this._init
        }
    })()
});


Extend current objects with jQuery

// Navigation component scripts
var bobcat = bobcat || {};

bobcat.components = $.extend(bobcat.components, {

    "navigation": (function() {
        this._init = function() {
            // some initial functions
        }

        return {
            init: this._init
        }
    })()
});


Encapsulation In JavaScript.

Example :


var mainmodule = {};

mainmodule.newModule = (function() {
    var that = this;
    this._setup = function() {
        // do some setup
    };

    this._init = function() {
        that._setup(); // and do more here
    };
    return {
        init: this._init
    }
})();


Note:

use that pattern

private vars with "_" prefix


How to create Shortcut for Netbeans in Ubuntu


My Ubuntu version 14.4 and Netbeance version 8.2

Create New File under :  /usr/share/applications$
File name : netbeans.desktop

[Desktop Entry]
Name=Netbeans
Encoding=UTF-8
Comment=Netbeans IDE 8.2
Exec=/bin/sh "/usr/local/netbeans-8.0.2/bin/netbeans" %U
Icon=/usr/share/app-install/icons/_usr_share_netbeans_7.0.1_nb_netbeans.png
Terminal=false
Type=Application
Categories=Development,IDE;
StartupNotify=false

How To Create Custom Block Programatically

===============
.info File
===============

name = custom_block
description = My Custom Block using module
core = 7.x

===============
.Module File
===============

<?php

/**
 * Implements hook_block_info().
 */
function custom_block_block_info() {
    $blocks = array();
    $blocks['my_block'] = array(
        'info' => t('My Custom Block'),
    );

    return $blocks;
}

/**
 * Implements hook_block_configure().
 */
function custom_block_block_configure($delta = '') {
    $form = array();


    switch ($delta) {
        case 'my_block' :
            // Text field form element
            $form['text_body'] = array(
                '#type' => 'text_format',
                '#title' => t('Enter your text here in WYSIWYG format'),
                '#default_value' => variable_get('text_variable', ''),
            );

            // File selection form element
            $form['file'] = array(
                '#name' => 'block_image',
                '#type' => 'managed_file',
                '#title' => t('Choose an Image File'),
                '#description' => t('Select an Image for the custom block.  Only *.gif, *.png, *.jpg, and *.jpeg images allowed.'),
                '#default_value' => variable_get('block_image_fid', ''),
                '#upload_location' => 'public://block_image/',
                '#upload_validators' => array(
                    'file_validate_extensions' => array('gif png jpg jpeg'),
                ),
            );
            break;
    }
    return $form;
}

/**
 * Implements hook_block_save().
 */
function custom_block_block_save($delta = '', $edit = array()) {
    switch ($delta) {
        case 'my_block' :
            // Saving the WYSIWYG text    
            variable_set('text_variable', $edit['text_body']['value']);

            // Saving the file, setting it to a permanent state, setting a FID variable
            $file = file_load($edit['file']);
            $file->status = FILE_STATUS_PERMANENT;
            file_save($file);
            $block = block_load('custom_block', $delta);
            file_usage_add($file, 'custom_block', 'block', $block->bid);
            variable_set('block_image_fid', $file->fid);
            break;
    }
}

/**
 * Implements hook_block_view().
 */
function custom_block_block_view($delta = '') {
    $block = array();

    switch ($delta) {
        case 'my_block' :
            $block['content'] = my_block_view();
            break;
    }

    return $block;
}

/**
 * Custom function to assemble renderable array for block content.
 * Returns a renderable array with the block content.
 * @return
 *   returns a renderable array of block content.
 */
function my_block_view() {
    $block = array();

    // Capture the image file path and form into HTML with attributes
    $image_file = file_load(variable_get('block_image_fid', ''));
    $image_path = '';

    if (isset($image_file->uri)) {
        $image_path = $image_file->uri;
    }

    $image = theme_image(array(
        'path' => ($image_path),
        'alt' => t('Image description here.'),
        'title' => t('This is our block image.'),
        'attributes' => array('class' => 'class_name'),
    ));

    // Capture WYSIWYG text from the variable
    $text = variable_get('text_variable', '');

    // Block output in HTML with div wrapper
    $block = array(
        'image' => array(
            '#prefix' => '',
            '#type' => 'markup',
            '#markup' => $image,
            'message' => array('#type' => 'markup', '#markup' => $text, '#suffix' => '')
        )
    );
    return $block;
}



moment.js date format

Moment.js set yyyy-mm-dd format date
  
moment().format('YYYY-MM-DD H:m:s');  

How to add missing date month year in mysql (php)

Hi 

I have tried many solutions with MySQL but at the end, i found solution with PHP
which  is best 


$begin = new DateTime('2016-01-20');
$end = new DateTime('2017-12-10');

while ($begin <= $end) {
    echo $begin->format('Y-m'), "n";
    $begin->modify('first day of next month');
}