Posted
on January 26, 2018, 2:31 pm,
by admin,
under
php.
$data['message'] = 'Simple Message';
$data['status'] = 'success';
header('Content-Type: application/json');
echo json_encode($data); |
Posted
on January 23, 2018, 4:27 pm,
by admin,
under
dictionary,
php.
Abstract class – is something between a regular class and a pure interface. The purpose of this is to provide a kind of template to inherit from and to force the inheriting class to implement the abstract methods.
Interface – is a special case of abstract classes where ALL methods are abstract.
Posted
on January 18, 2018, 9:37 am,
by admin,
under
bash.
Show next line after matched line
grep -A1 searchpattern filename |
Show next 2 lines after matched line
grep -A2 searchpattern filename |
Show previous line after matched line
grep -B1 searchpattern filename |
Posted
on January 16, 2018, 9:34 am,
by admin,
under
mysql.
CREATE TABLE newtable LIKE oldtable; |
Posted
on January 11, 2018, 3:35 pm,
by admin,
under
mysql.
CREATE PROCEDURE example1()
label1:BEGIN
DECLARE rowCount INT DEFAULT 0;
DECLARE i INT DEFAULT 0;
SELECT COUNT(*) INTO rowCount FROM my_table;
WHILE (i <= rowCount) DO
SELECT i;
SET i = i+1000;
END WHILE;
END; |
Posted
on January 11, 2018, 3:33 pm,
by admin,
under
mysql.
The difference with WHILE is that it execute statement before checking the condition. As a result, it iterates one more time than WHILE does.
CREATE PROCEDURE example2()
label1:BEGIN
DECLARE rowCount INT DEFAULT 0;
DECLARE i INT DEFAULT 0;
SELECT COUNT(*) INTO rowCount FROM my_table;
REPEAT
SELECT i;
SET i = i+1000;
UNTIL i > rowCount
END REPEAT;
END; |
Posted
on December 19, 2017, 4:59 pm,
by admin,
under
mysql.
In MySQL, function is different than procedure by returning the value and can be called within SELECT statement.
DETERMINISTIC means that the function always produces same results for the same input parameters.
CREATE FUNCTION `Sample`(parameter VARCHAR(10)) RETURNS TINYINT(3) UNSIGNED
DETERMINISTIC
BEGIN
DECLARE myfunctionID TINYINT UNSIGNED;
IF parameter = 'sample1' THEN
SET returnID = 1;
ELSEIF parameter = 'sample2' THEN
SET returnID = 2;
ELSEIF parameter = 'sample3' THEN
SET returnID = 3;
END IF;
END IF;
RETURN myfunctionID;
END |
Posted
on November 22, 2017, 1:28 pm,
by admin,
under
dns,
mail.
Step 1. Add SPF record to your DNS server
Create TXT record type and add the following text without quotes “”
@ TXT "v=spf1 a mx include:myrelay.com ~all" |
Step 2. Check if SPF record is added correctly
username@laptop:/home/username# dig myhostname.com TXT
<<>> DiG 9.10.3-P4-Ubuntu <<>> myhostname.com TXT
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62028
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4000
;; QUESTION SECTION:
;myhostname.com. IN TXT
;; ANSWER SECTION:
myhostname.com. 86400 IN TXT "v=spf1 a mx include:myrelay.com ~all"
;; Query time: 7 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Wed Nov 22 13:36:40 GMT 2017
;; MSG SIZE rcvd: 104 |
Step 3. Test it by sending email to your gmail account, then go the receiver’s mailbox and check email source header
Received-SPF: pass (google.com: domain of www-data@myhostname.com designates 24.33.20.159 as permitted sender) client-ip=24.33.20.159;
Authentication-Results: mx.google.com;
spf=pass (google.com: domain of www-data@myhostname.com designates 24.33.20.159 as permitted sender) smtp.mailfrom=www-data@myhostname.com |
Posted
on November 22, 2017, 12:35 pm,
by admin,
under
apache,
tips.
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s on(s)|offs()
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R] |
Posted
on September 22, 2017, 12:56 pm,
by admin,
under
mysql.
SELECT COUNT(*) FROM information_schema.TABLES WHERE table_schema = 'databasename'; |