Java Optional

JAVA OPTIONAL CLASS
public static void main(String[] args) {

  Optional<String> hello = Optional.ofNullable(null);

   // 1. Optional Use:
  // check value is present in hello
   System.out.println(hello.isPresent());
  // check if hello(v) is empty
   System.out.println(hello.isEmpty());


  // 2. orElse:  if hello doesn't contain any value
  // then $hello = world
   String orElse = hello
          .map(String::toUpperCase)
           .orElseGet(() -> {
               //.. extra computation to re

JPA: Find student with email address

Custom findStudentByEmail function will fetch student information using student email address.
/*          FIND SOMEONE WITH GIVEN EMAIL ADDRESS
             * ==========================================================================*/
            studentRepository
                    .findStudentByEmail("ahmed.ali@gmail.com")
                    .ifPresentOrElse(
                            System.out::println,
                            ()-> System.out.println("Student with email ahmed.ali@gmail.com not found"));

How to use JPARepository

# JPA Command Line Runner: a full description of how to write commandline runner code to do db operations using JPARepository
@Bean
    CommandLineRunner commandLineRunner(StudentRepository studentRepository) {
        return args -> {
            Student maria = new Student(
                    "Maria",
                    "Jones",
                    "maria.jones@gmail.com",
                    21
            );

            Student ahmed = new Student(
                    "Ahmed",
                    "Ali",
                    "ahmed.ali@gmail.com",
                    18
            );

           

event handler inside render method in class component

import React from 'react';
import ReactDOM from 'react-dom';

class Button extends React.Component {
  scream() {
    alert('AAAAAAAAHHH!!!!!');
  }

  render() {
    return <button onClick={this.scream}>AAAAAH!</button>;
  }
}

ReactDOM.render(<Button />, document.getElementById('app'));

class with getter method and this

mport React from 'react';
import ReactDOM from 'react-dom';

class MyName extends React.Component {
	// name property goes here:
get name() {
  return 'Andy';
}

  render() {
    return <h1>My name is {this.name}.</h1>;
  }
}

ReactDOM.render(<MyName />, document.getElementById('app'));

class component for react

quote maker from codecademy
import React from 'react';
import ReactDOM from 'react-dom';

class QuoteMaker extends React.Component {
  render() {
    return (
      <blockquote>
  <p>
    What is important now is to recover our senses.
  </p>
  <cite>
    <a target="_blank" 
      href="https://en.wikipedia.org/wiki/Susan_Sontag">
      Susan Sontag
    </a>
  </cite>
</blockquote>
    );
  }
} 

ReactDOM.render(
  <QuoteMaker />,
  document.getElementById('app')
);

olympic_medal.rb

mixins example in Ruby
# frozen_string_literal: true

# OlympicMedal is class that represents an olympic medal
class OlympicMedal
  # <, <=, >=, >, ==, !=, <=>, .between?
  include Comparable

  MEDAL_VALUES = { Gold: 3, Silver: 2, Bronze: 1 }.freeze

  attr_reader :type

  def initialize(type, weight)
    @type = type
    @weight = weight
  end

  def <=>(other)
    if MEDAL_VALUES[type] < MEDAL_VALUES[other.type]
      -1
    elsif MEDAL_VALUES[type] == MEDAL_VALUES[other.type]
      1
    else
      0
    end
  end

Conditional Menus - Plugins

https://wordpress.org/plugins/conditional-menus/

Resize gpt partition

/sbin/parted /dev/sdm resizepart 1 yes 100%

Vue nextTick

https://dmitripavlutin.com/vue-next-tick/

シェーダー基礎(three.js)

<canvas class="webgl"></canvas>

<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>

Create new item with Patch command

#patch #create #item #sql #sharepoint #dataverse #record
Patch(Resources, Defaults(Resources), {Name: textName.Text, Title: textTitle.Text})

Application Feature

USE OnlineBanking

select A.Name, AF.ApplicationID, F.Name, AF.FeatureID from Applications_Features AF 
JOIN Applications A 
ON A.ID = AF.ApplicationID 
JOIN Features F
ON F.ID = AF.FeatureID

Fedora36: install Nvidia drivers

1. **Install the tools required for auto signing to work**\
    `sudo dnf install kmodtool akmods mokutil openssl`

2. **Generate a signing key**\
    `sudo kmodgenca -a`

3. **Initiate the key enrollment**\
This will make Linux kernel trust drivers signed with your key\
    `sudo mokutil --import /etc/pki/akmods/certs/public_key.der`\
    You will be asked to enter a password, it doesn’t have to be very strong, just make sure to remember it. You’ll only need it once during step 5.\

4. **Reboot

OOPS | Inheritance the extension of the class

<?php
//Inheritance
//Extension of one class

Class Room
{
	public $name;
    public $size;
    
    function __construct($name,$size)
    {
    	$this->name = $name;
        $this->size = $size;
    }
    
    function intro()
    {
    	echo "This is a ".$this->name;
    }
}

Class Kitchen extends Room
{
	function message()
    {
    	echo "This is a ".$this->name." and it is ".$this->size;
    }
}

$kitchen = new Kitchen("Kithen","large");
$kitchen->intro();
$ki

OOPS | Access modifier functions

<?php
//Access modifiers
//Public : Accessed from anywhere
//Protected : Accessed from that class and class derived from it
//Private : Only within class
//Mistake forgot to write function

Class Room {
	public $name;
    protected $size;
    private $shelf;
    
    function set_name($name)
    {
    	$this->name = $name;
    }
    
    protected function set_size($size)
    {
    	$this->size = $size;
    }
    
    private function set_shelf($shelf)
    {
    	$this->s