Results: 1580
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
PHP / JavaScript differences
PHP variable declaration
$variable = 1;
JS alternative
let variable = 1;
PHP - check if the variable exists
if (isset($variable))
JS alternative
if (typeof variable !== "undefined")
PHP count array elements
$count = count([2, 3, 4]);
JS alternative
let count = [2, 3, 4].length;
PHP count letters in the string
$len = strlen('some string');
JS alternative
let len = 'some string'.length;
PHP absolute value of a given number
$variable = abs(-5);
JS alternative
let variable = Math.abs(-5);
PHP - power of a number
$square = pow(5, 2);
JS alternative
let square = Math.pow(5, 2);
PHP - square root of a number
$square_root = sqrt(16);
JS alternative
let square_root = Math.sqrt(16);
PHP - minimum number
$max = min(2, 3, 4);
JS alternative
let max = Math.min(2, 3, 4);
PHP - maximum number
$max = max([2, 3, 4]);
JS alternative
let max Math.max(...[2, 3, 4])
PHP calculates sum of the array elements
$sum = array_sum([2, 3, 4]);
JS alternative
let sum = 0;
let arr = [1, 2, 3];
for (let value of arr) {
    sum += value;
}
Another way to calculate the same
let arr = [1, 2, 3];
let sum = 0;
let len = arr.length;
for (let i = 0; i < len; sum += arr[i++]);
PHP - string position
$pos = strpos('Hello world', 'world');
JS alternative
let pos = 'Hello world'.indexOf('world');
PHP - edit letter in a string
$string[4] = 'X';
JS alternative
string = string.substring(0, 4) + 'X' + string.substring(5);
PHP convert the variable to integer
$variable = intval(5.5);
JS alternative
let variable = parseInt(5.5);
PHP - explode the sentence
$sentence = "Lorem ipsum dolor st amet";
$words = explode(" ", $sentence);
JS alternative
let sentence = "Lorem ipsum dolor st amet";
let words = sentence.split(" ");
by Valeri Tandilashvili
2 years ago
0
PHP
1
git merge --squash
The git merge --squash command combines changes from one branch into another branch but does not create a merge commit. Step 1: Initialize project
git init
Step 2: create index.html file and 2 commit m1,m2 add text "m1" into index.html and commit as m1

echo "m1" > index.html
git add .
git commit -m "m1" 
add text "m2" into index.html and commit as m2

echo "m2" >> index.html
git add .
git commit -m "m2" 
Step 3: create feature branch and checkout
git checkout -b feature
Step 4: create feature folder&file create feature.html into the feature folder and add text "f1" then commit as f1

echo "f1" >> feature/feature.html
git add .
git commit -m "f1" 
Step 5: Checkout to master
git checkout master
Step 6: add text "m3" into index.html and commit as m3

echo "m3" >> index.html
git add .
git commit -m "m3" 
Step 7: Checkout to feature
git checkout feature
Step 8: add text "f2" into feature.html and commit as f2

echo "f1" >> feature/feature.html
git add .
git commit -m "f2" 
Step 9: Checkout to master
git checkout master
Step 10: Merge feature branch into master with squash
git merge --squash feature
Step 11: See git status because files we will have into the staging area and we need create a commit for it

git status
git commit -m "Merge feature branch into master"
by Luka Tatarishvili
1 year ago
0
Git
commands
1
The new note
source 
code4123 new code line one more line1h
by Valeri Tandilashvili
1 year ago
0
CSS
1
Trigger types
Trigger can run
before
or
after
some database event. The event can be
insert
,
update
or
delete
. It means there are six types of triggers:
before / after
insert
before / after
update
before / after
delete
by Valeri Tandilashvili
4 years ago
0
MySQL
TRIGGERS
1
Create TRIGGER before INSERT
Creates trigger that runs
before
insert
and checks & replaces gender values
DROP TRIGGER IF EXISTS before_student_insert;

DELIMITER $$

    CREATE TRIGGER before_student_insert BEFORE INSERT 
    ON students
    FOR EACH ROW 
    BEGIN

    INSERT INTO log (description)
    VALUES ('One student will be inserted');
    
    IF (NEW.gender = 'Female') THEN
        SET NEW.gender = 2;
    ELSE
        SET NEW.gender = 1;
    END IF;

    END$$

DELIMITER ;
by Valeri Tandilashvili
4 years ago
0
MySQL
TRIGGERS
1
Foreign key constraint Referential Actions
MySQL supports several referential actions:
CASCADE
- deletes or updates appropriate rows in the child table
SET NULL
- sets the foreign key column of the child table to
NULL
RESTRICT
- rejects the operation for the parent table
NO ACTION
- equivalent to
RESTRICT
Note:
RESTRICT
is the same as omitting the
ON DELETE
or
ON UPDATE
clause, which means that it's default action
by Valeri Tandilashvili
4 years ago
0
MySQL
FOREIGN KEY
1
Create function salary level
DROP FUNCTION IF EXISTS getIncomeLevel;

DELIMITER //

CREATE FUNCTION getIncomeLevel ( monthly_value INT )
RETURNS varchar(20)

BEGIN

   DECLARE income_level varchar(20);

   IF monthly_value <= 4000 THEN
        SET income_level = 'Low Income';
   ELSEIF monthly_value > 4000 AND monthly_value <= 7000 THEN
        SET income_level = 'Avg Income';
   ELSE
        SET income_level = 'High Income';
   END IF;

   INSERT INTO log (description)
   VALUES ('getIncomeLevel function was called');

   RETURN income_level;

END; //

DELIMITER ;
After creating the function we can call it:
SELECT getIncomeLevel(450)
by Valeri Tandilashvili
4 years ago
0
MySQL
User defined functions
1
Create procedure that checks and prints income level
DROP PROCEDURE IF EXISTS printIncomeLevel;

DELIMITER //

CREATE PROCEDURE printIncomeLevel (IN monthly_value INT)

BEGIN

   DECLARE income_level varchar(20);

   IF monthly_value <= 4000 THEN
        SET income_level = 'Low Income';
   ELSEIF monthly_value > 4000 AND monthly_value <= 7000 THEN
        SET income_level = 'Avg Income';
   ELSE
        SET income_level = 'High Income';
   END IF;

   INSERT INTO log (description)
   VALUES ('getIncomeLevel procedure was called');

   SELECT income_level;

END;
After creating the procedure, we can call it using
CALL
keyword:
CALL printIncomeLevel(450)
by Valeri Tandilashvili
4 years ago
0
MySQL
User defined procedures
1
Creates one
INDEX
with several fields for table
notes
. Combines the two fields
title, description
to create one index
CREATE TABLE note (
    id int AUTO_INCREMENT,
    note_id int,
    title varchar(50),
    description varchar(50),
    PRIMARY KEY(id, note_id),
    INDEX ind_title_description (title, description)
);
If we need to filter the result with both fields
(title, description)
at the same time, then
ind_title_description
is a great index
by Valeri Tandilashvili
4 years ago
0
MySQL
CREATE TABLE
Index
Full MySQL Course for Beginners
1
Create table and add several INDEXES
Creates the table
note
and adds several indexes
(ind_note_id, ind_title_description)
at the same time
CREATE TABLE note (
    id int AUTO_INCREMENT,
    note_id int,
    title varchar(50),
    description varchar(50),
    PRIMARY KEY(id, note_id),
    INDEX ind_note_id (note_id),
    INDEX ind_title_description (title, description)
);
by Valeri Tandilashvili
4 years ago
0
MySQL
CREATE TABLE
Index
1
Results: 1580