Skip to content

Instantly share code, notes, and snippets.

View vanleantking's full-sized avatar
🤣

Le Van vanleantking

🤣
  • U
  • Binh Thanh
View GitHub Profile
@vanleantking
vanleantking / One or more indexers are invalid. Make sure your Magento cron job is running.
Created August 20, 2018 16:46
One or more indexers are invalid. Make sure your Magento cron job is running.
Go to Magentto root from command line and run following command.
php bin/magento indexer:reindex
@vanleantking
vanleantking / how long text in MySQL can be store
Created August 21, 2018 09:02
how long text in MySQL can be store
Type | Maximum length
-----------+-------------------------------------
TINYTEXT | 255 (2 8−1) bytes
TEXT | 65,535 (216−1) bytes = 64 KiB
MEDIUMTEXT | 16,777,215 (224−1) bytes = 16 MiB
LONGTEXT | 4,294,967,295 (232−1) bytes = 4 GiB
Note that the number of characters that can be stored in your column will depend on the character encoding.
@vanleantking
vanleantking / gist:d8afb057e3b96c3ac6dbca0e69979abf
Created August 22, 2018 03:42
PHP # truncate text with saving html structure and doesn't breaking last word
<?php
class String{
public static function truncate($text, $length = 100, $ending = '...', $exact = false, $considerHtml = true) {
if ($considerHtml) {
// if the plain text is shorter than the maximum length, return the whole text
if (strlen(preg_replace('/<.*?>/', '', $text)) <= $length) {
return $text;
}
// splits all html-tags to scanable lines
preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER);
@vanleantking
vanleantking / truncate_html.php
Created August 22, 2018 09:20 — forked from andykirk/truncate_html.php
PHP Truncate HTML Function
/**
* truncate_html()
*
* Truncates a HTML string to a given length of _visisble_ (content) characters.
* E.g.
* "This is some <b>bold</b> text" has a visible/content length of 22 characters,
* though the total string length is 29 characters.
* This function allows you to limit the visible/content length whilst preserving any HTML formatting.
*
* @param string $html
<?php
/**
* Website: http://sourceforge.net/projects/simplehtmldom/
* Acknowledge: Jose Solorzano (https://sourceforge.net/projects/php-html/)
* Contributions by:
* Yousuke Kumakura (Attribute filters)
* Vadim Voituk (Negative indexes supports of "find" method)
* Antcs (Constructor with automatically load contents either text or file/url)
*
* all affected sections have comments starting with "PaperG"
@vanleantking
vanleantking / split string content by white space (space, tab, newline)
Created September 1, 2018 04:46
split string content by white space (space, tab, newline)
$segments = preg_split('/[\s]+/', $string );
check url exist in string
filter_var($process_content, FILTER_VALIDATE_URL)
@vanleantking
vanleantking / send custom header post method curl exec
Created September 3, 2018 04:48
send custom header post method curl exec
$ch = curl_init(); // create curl handle
$url = "url";
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, array('data' => data_value));
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'param1: value_param1',
'Content-Type: application/json',
@vanleantking
vanleantking / config logger phalcon
Created September 5, 2018 02:11
config logger phalcon
$di->setShared('logger', function(){
$formatter = new \Phalcon\Logger\Formatter\Line('%date% %type% %message%');
$logger = new \Phalcon\Logger\Adapter\File('phalcon.log');
$logger->setLogLevel(\Phalcon\Logger::DEBUG);
$logger->setFormatter($formatter);
return $logger;
});
@vanleantking
vanleantking / add event when javascript loading success
Created September 17, 2018 15:44
add event when javascript loading success
var gptads = document.createElement('script');
gptads.setAttribute('type','text/javascript');
gptads.setAttribute('src', 'your_source_file');
if (gptads.addEventListener)
gptads.addEventListener('load', loadFunc, false);
document.getElementsByTagName('head')[0].appendChild(gptads);
function loadFunc() {
document.getElementById('txt_interests').innerHTML = interests;
document.getElementById('txt_gender').innerHTML = gender;
@vanleantking
vanleantking / javascript_loader.js
Created September 18, 2018 14:31 — forked from hagenburger/javascript_loader.js
Dynamically load JavaScript files with callback when finished
// Example:
JavaScript.load("/javascripts/something.js");
// With callback (that’s the good thing):
JavaScript.load("http://www.someawesomedomain.com/api.js", function() {
API.use(); // or whatever api.js provides ...
});