Monday, 31 December 2018

code for replace null with quotes

https://gist.github.com/tureki/7af3ea2554eba60c34c5 $value = array(
    "deep"=>1,
    "data"=>null,
"node"=>array(
        "deep"=>2,
        "data"=>null,
"node"=>array(
            "deep"=>3
        )
    ),
    null
);

array_walk_recursive($value, function (&$item, $key) {
$item = null === $item ? '' : $item;
});

echo json_encode($value);

url regex validation

preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $url)

Wednesday, 26 December 2018

winston logger integration

https://thisdavej.com/using-winston-a-versatile-logging-library-for-node-js/

iterate java object ket and value

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.   ;

public class Main {

  private Main() {}

  public static Map<String, Object> getFieldNamesAndValues(final Object obj, boolean publicOnly)
    throws IllegalArgumentException,IllegalAccessException
  {
    Class<? extends Object> c1 = obj.getClass();
    Map<String, Object> map = new HashMap<String, Object>();
    Field[] fields = c1.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
      String name = fields[i].getName();
      if (publicOnly) {
        if(Modifier.isPublic(fields[i].getModifiers())) {
          Object value = fields[i].get(obj);
          map.put(name, value);
        }
      }
      else {
        fields[i].setAccessible(true);
        Object value = fields[i].get(obj);
        map.put(name, value);
      }
    }
    return map;
  }

  /**
   * @param args
   */
  public static void main(String[] args) throws Exception {

    Dummy dummy = new Dummy();
    System.out.println(Main.getFieldNamesAndValues(dummy,true));
    System.out.println(Main.getFieldNamesAndValues(dummy,false));
    /*
     * output :
     *  {value3=43, value1=foo, value2=42}
     *  {value3=43, value4=bar, value1=foo, value2=42}
     */
  }
}

class Dummy {
  public String value1 = "foo";
  public int value2 = 42;
  public Integer value3 = new Integer(43);
  private String value4 = "bar";
}

Thursday, 20 December 2018

duplicate class issue in netbens

https://stackoverflow.com/questions/19318704/java-duplicate-class

Wednesday, 19 December 2018

async await

https://hackernoon.com/6-reasons-why-javascripts-async-await-blows-promises-away-tutorial-c7ec10518dd9

git special command

check file difference 

git diff file_2.php

get date difference

https://stackoverflow.com/questions/13194322/php-regex-to-check-date-is-in-yyyy-mm-dd-format

$date="2012-09-12";

if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/",$date)) {
    return true;
} else {
    return false;
}

http://thisinterestsme.com/calculating-difference-dates-php/

<?php
 
//Our "then" date.
$then = "2009-02-04";
 
//Convert it into a timestamp.
$then = strtotime($then);
 
//Get the current timestamp.
$now = time();
 
//Calculate the difference.
$difference = $now - $then;
 
//Convert seconds into days.
$days = floor($difference / (60*60*24) );
 
echo $days;

Monday, 10 December 2018

jacson object mapper

https://www.baeldung.com/jackson-object-mapper-tutorial

Friday, 7 December 2018

password encryption in java

https://howtodoinjava.com/security/how-to-generate-secure-password-hash-md5-sha-pbkdf2-bcrypt-examples/