Skip to content

Instantly share code, notes, and snippets.

@RakibSiddiquee
RakibSiddiquee / content_format.php
Created October 13, 2022 12:23
Format plain url to link and embed video in rich text editor content in PHP
public function formatBody($value){
// The Regular Expression filter
$reg_exUrl = '#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#';
return Str::of($value)->replaceMatches($reg_exUrl, function ($match) {
$parsedUrl = parse_url($match[0]);
if (($parsedUrl['host'] == 'youtube.com' || $parsedUrl['host'] == 'www.youtube.com') && isset($parsedUrl['query'])) {
parse_str($parsedUrl['query'], $key);
@RakibSiddiquee
RakibSiddiquee / Docker Commands
Last active November 12, 2022 13:39
Docker commands
docker ps - to show running containers
docker ps -a -- to show all containers
docker images - to show images
Pull an image:
--------------
docker pull <image>:<tag>
docker pull postgres:14-alpine - pull postgres image
@RakibSiddiquee
RakibSiddiquee / xampp-in-different-port.txt
Created September 30, 2019 07:12
Run xampp and mysql in different port
Open httpd.conf and change Listen 80 to Listen 8080
Mysql:
Change the php.ini and my.ini port 3306 to 3307
Restart the xampp, if not work restard the pc also.
@RakibSiddiquee
RakibSiddiquee / age-count.js
Created February 27, 2019 11:54
Count age from a given birthday in Javascript.
birthday = '1987-05-04';
age = ((Date.now() - Date.parse(birthday)) / 31557600000).toFixed(1);
alert(age);
@RakibSiddiquee
RakibSiddiquee / makeSlugMySql.sql
Created January 21, 2019 11:04
Make slug of a column in MySQL database and update
UPDATE table SET domain = LOWER(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(TRIM(name), ':', ''), '’', ''), ')', ''), '(', ''), ',', ''), '\\', ''), '\/', ''), '\"', ''), '?', ''), '\'', ''), '&', ''), '!', ''), '.', ''), ' ', '-'), '--', '-'), '--', '-'))
@RakibSiddiquee
RakibSiddiquee / unique-number.php
Created September 8, 2018 13:00
PHP unique number generate function
<?php
function uniqueNumber(){
$unqNo = strtotime(date("Ymdhis"))*999;
return $unqNo;
}
@RakibSiddiquee
RakibSiddiquee / watermark.php
Created July 17, 2018 10:47
Place watermark over an image in PHP or place any image over another image
<?php
// Load the logo stamp and the photo to apply the watermark to
$logo = imagecreatefrompng('https://cdn.jagonews24.com/media/common/og-logo.png');
//$logo = imagecolorallocate($logo,0,0,0);
$img = imagecreatefromjpeg('https://cdn.jagonews24.com/media/imgAll/2018June/shahin-cover-20180711084009.jpg');
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 10;
@RakibSiddiquee
RakibSiddiquee / php-pagination.txt
Created February 19, 2018 14:52
Basic php PDO pagination
<!DOCTYPE html>
<html lang="en">
<head>
<title>Fan Club List</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
@RakibSiddiquee
RakibSiddiquee / recapcha.php
Created January 29, 2018 07:30
Google recapcha v2 implementation in php
<?php
//To start using reCAPTCHA, you need to sign up for an API key pair for your site from https://www.google.com/recaptcha/admin#list
$siteKey = "6LcqlUAUAAAAAFqZqFzhtEHApepRVPtv-Xynkub9";
$secretKey = "6LcqlUAUAAAAADt1b9okVcSrgC0461J9NyTzNqlY";
$gres = $_POST['g-recaptcha-response'];
$ip = $_SERVER['REMOTE_ADDR'];
$suc = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secretKey.'&response='.$gres.'&remoteip='.$ip);
$res = json_decode($suc);
@RakibSiddiquee
RakibSiddiquee / Laravel-custom-validation-message.txt
Created January 8, 2018 20:31
Laravel custom validation error message
$this->validate($request, [
'heading' => 'required',
'category' => 'required',
'details' => 'required',
],[
'heading.required' => 'লেখার শিরোনাম প্রদান করুন!',
'category.required' => 'একটি ক্যাটাগরি নির্বাচন করুন!',
'details.required' => 'বিস্তারিত লেখা প্রদান করুন!',
]);