JAVA stream

JAVA stream

Stream is used in Manipulating collection 


List<Integer> num = new ArrayList<>();

num.add(10);
num.add(20);
num.add(30);
num.add(40);

List<Integer> cubeList = num.stream().map(x -> x*x*x).collect(Collection.toList());

// get string from list to collect string starts with a

List<String> strlist = strlist.stream().filter(s -> s.startsWith("a")).collect(Collection.toList());


To take sum of list
int sum = numList.stream().reduce(0, (and, i) ->  ans + i );



JAVA  List LinkedList HashSet HashMap TreeSet TreeMap Queue

JAVA List LinkedList HashSet HashMap TreeSet TreeMap Queue

 

import java.util.ArrayList


List<Integer> arrList = new ArrayList<Integer>(10);

arrList.add(1);

arrList.add(2);

arrList.add(3);

arrList.add(4);

arrList.add(5);

arrList.add(6);

System.out.println(arrList);  1,2,3,4,5,6

arrList.remove(3);  remove 3rd element that is 4 


LinkedList

LinkedList<String> linkist = new LinkedList<String>();

linkist .add("A");
linkist .addLast("C");
linkist .addFirst("D");
linkist .add(2,"B");

// D A B C

linkist .remove("C");
linkist .add(2); //by position 
linkist .removeFirst("A");
linkist .removeLast("A");


Hashset

Set<String> hashset = new HashSet<>();

boolean ret = bhashset.add("A"); //true if added false if not added
hashset.add("B");
hashset.add("B"); ///return false here

hashset.contains("A");

hashset.remove("A");


HashMap

Map<String, Integer> hmap = new HashMap<>();

hmap.put("a",10);
hmap.put("b",20);
hmap.put("c",30);

// { a=10, b=20, c=30}
hmap.size();  // 3 

hmap.containsKey("a"); //boolean 

hmap.get("a");

hmap.keySet();  // array of keys

for(String k: hmap.keySet()){
   // hmap.get(k);
}

for(Entry <String, Integer> data : hmap.entrySet()){
   // data.getKey();  

   // data.getValue();
}


TreeSet

Naturally sorted in Treeset

TreeSet<String> tset = new TreeSet<String>();

tset.add("B");
tset.add("A");
tset.add("C");
tset.add("C");

// A, B, C   // sort //ordered by default


TreeMap

Naturally sorted in Treeap

Map< Integer, String> tmap= new HashMap<>();

tmap.put(1,"a");
mtap.put(2,"b");
tmap.put(3,"c");

// {1=a,2=b,3=c}

Map< String, Integer> tmap= new HashMap<>();

tmap.put("b",2);
mtap.put("a",1);
tmap.put("c",3);

// {a=1,b=2,c=3}


Stacks

Stack <String> stack = new Stack<>();

stack.push("A");
stack.push("B");
stack.push("C");

String  poped = stack.pop(); // C  remove from stack

String  peeked = stack.peek(); // C , doesnt remove from stack

//Stack is filo


Queue

// fifo arrangement

Queue<> que = new PriorityQueue<>();

que .push("A");
que .push("B");
que .push("C");


que.remove(); // 

que.peek(); // 

que.poll(); // 





JS templating and rendering json data

JS templating and rendering json data

JS templating and rendering json data

 

<script type="text/template" data-template="apkItem">

<div class="apk-box">

<div class="apk-version d-flex align-items-center justify-content-between">

<div class="divider">

<div class="title">

<span class="ver-name">${version_name} </span><span class="date">${updated_on}</span>

</div>

<a class="ver-link" href="javascript:void(0);">${apk_filename}</a>

</div>

<a style="display:none" href="./app/${apk_filename}" class="dl-btn download_allow" data-download-allow="${download_allow}">

<svg xmlns="http://www.w3.org/2000/svg" height="48" viewBox="0 96 960 960" width="48"><path d="M220 896q-24 0-42-18t-18-42V693h60v143h520V693h60v143q0 24-18 42t-42 18H220Zm260-153L287 550l43-43 120 120V256h60v371l120-120 43 43-193 193Z"/></svg>

</a>

</div>

<div class="apk-info">

<span class="memo">メモ</span><br>

<p>${update_memo}</p>

</div>

</div>

</script>

<script type="text/javascript" src="./js/jquery-3.6.4.js"></script>


<script type="text/javascript">

function render(props) {

return function (tok, i) {

return (i % 2) ? props[tok] : tok;

};

}

$(document).ready(function(){

$.getJSON('./json/data.json', function (data) {

           

            var header = data.app_header;

            var headerEl = $(".apk-logo-wrapper");

            var headerTpl = $('script[data-template="header"]').text().split(/\$\{(.+?)\}/g);


            headerEl.html(headerTpl.map(render(header)).join(''));


            var list = data.version_info;

            var listEl = $(".apk-wrapper");

            var listTpl = $('script[data-template="apkItem"]').text().split(/\$\{(.+?)\}/g);

            listEl.html(list.map(function (item) {

return listTpl.map(render(item)).join('');

}));


            $(".download_allow[data-download-allow='1']").show();

            });

});

</script>


  $db             = app('firebase.firestore')->database();

    

    $firebaseDoc    =   $db->collection(config('constants.firebase_collection_timesles'))->document($timesale->id);


    $message = "";

    if(!empty($timesale->product) && !empty($timesale->product->column_1_191)) {

        $message = $timesale->product->column_1_191;

    }


    $update = $firebaseDoc->set([


       

    ],['merge'=>true]);



Angular commands

Angular commands

 


Angular 

Generate Module:

ng g m modules\<module-name> --routing


Angular commands 


Generate Component:

ng g c modules\<module-name>\components\<component-name>


Generate Model (Class):

ng g class modules\<module-name>\models\<model-name> --type=model


Generate Service:

ng g s modules\<module-name>\services\<service-name>


Generate guard:

ng g guard shared\guard/...

Recreate migration file from database and tables.

 


Laravel Migration

Recreate migration file from database and tables.

Package : https://github.com/kitloong/laravel-migrations-generator


php artisan migrate:generate 


Possible error: Unknown database type bit requested, Doctrine\DBAL\Platforms\PostgreSQL94Platform may not support it.




Temporary Fixes:

Edit file in line 423: 

vendor\doctrine\dbal\src\Schema\PostgreSQLSchemaManager.php 


 if($dbType=='bit') {

            $dbType = "boolean";

   }

Execute : skipping view and procedure 

php artisan migrate:generate   --skip-views --skip-proc

Japanese text validation with regex

Japanese text validation with regex

 Japanese text validation with regex

1. Japanese double byte, full and half width character validation and sample code for angular.
2. Creating custom validation in angular reactive form




export const regHiragana = /[\u3040-\u309F]+/g;
export const regKanji = /[\u3400-\u4DB5\u4E00-\u9FCB\uF900-\uFA6A]+/g;
export const regKatakanFull = /[\u30A0-\u30FF]+/g;
export const regKatakanHalf = /[\uFF5F-\uFF9F]+/g;
export const regAlphaNumeric = /[\w\d]+/g
export const regAddr01N = /[\uFF5F-\uFF9F\w\d\u0020]+/g;


function isJapChar ($str: string, regex: RegExp)
{
  let res = $str.match(regex);
  if(res != null){
    if (res[0] == $str) {
      return true;
    }
  }
  return false;
}


export function katakanaValidate(control: AbstractControl):
{ [key: string] : any} | null | void {
  const vals : string = control.value;
  let pattern = regKatakanFull;

  if(isJapChar(vals, pattern )){
 
    return null;
  }    
  return { 'katakanaValidate': true};
}

export function alphaNumericValidate(control: AbstractControl):
{ [key: string] : any} | null | void {
  const vals : string = control.value;
  let pattern = regAlphaNumeric;
  if((vals == '') || isJapChar(vals, pattern )){
    return null;
  }    
  return { 'alphaNumericValidate': true};
}

export function doubleByteValidate(control: AbstractControl):
{ [key: string] : any} | null | void {
  const vals : string = control.value;


  if((vals == '')
|| isJapChar(vals, regHiragana )
|| isJapChar(vals, regKanji )
|| isJapChar(vals, regKatakanFull )
|| isJapChar(vals, regKatakanHalf )){
    return null;
  }    
  return { 'doubleByteValidate': true};
}


2. validation rule in angular
nickname: ['', [Validators.required, doubleByteValidate, Validators.maxLength(20)]],