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 / php-html-css-js-minifier.php
Created July 23, 2018 07:41 — forked from taufik-nurrohman/php-html-css-js-minifier.php
PHP Function to Minify HTML, CSS and JavaScript
<?php
// Based on <https://github.com/mecha-cms/extend.minify>
define('MINIFY_STRING', '"(?:[^"\\\]|\\\.)*"|\'(?:[^\'\\\]|\\\.)*\'');
define('MINIFY_COMMENT_CSS', '/\*[\s\S]*?\*/');
define('MINIFY_COMMENT_HTML', '<!\-{2}[\s\S]*?\-{2}>');
define('MINIFY_COMMENT_JS', '//[^\n]*');
define('MINIFY_PATTERN_JS', '/[^\n]+?/[gimuy]*');
define('MINIFY_HTML', '<[!/]?[a-zA-Z\d:.-]+[\s\S]*?>');
@vanleantking
vanleantking / xampp_php7_xdebug.md
Created July 28, 2018 06:29 — forked from odan/xampp_php7_xdebug.md
Installing Xdebug for XAMPP

Installing Xdebug for XAMPP with PHP 7.x

Requirements

Setup

@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
@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 ...
});
@vanleantking
vanleantking / GoMgoSample-1.go
Created October 11, 2018 13:43 — forked from 345161974/GoMgoSample-1.go
Sample Go and MGO example
type (
// BuoyCondition contains information for an individual station.
BuoyCondition struct {
WindSpeed float64 `bson:"wind_speed_milehour"`
WindDirection int `bson:"wind_direction_degnorth"`
WindGust float64 `bson:"gust_wind_speed_milehour"`
}
// BuoyLocation contains the buoy's location.
BuoyLocation struct {
@vanleantking
vanleantking / .Title
Created October 14, 2018 09:12 — forked from congjf/.Title
Using MongoDB in golang with mgo
Using MongoDB in golang with mgo
@vanleantking
vanleantking / html_tokens.go
Created October 23, 2018 02:18 — forked from xeoncross/html_tokens.go
A simple HTML doc parser in golang that sends the tokens we are looking for back to the caller over a channel.
package main
import (
"fmt"
"strings"
"golang.org/x/net/html"
)
func main() {
@vanleantking
vanleantking / golang-tls.md
Created October 24, 2018 06:28 — forked from denji/golang-tls.md
Simple Golang HTTPS/TLS Examples

Moved to git repository: https://github.com/denji/golang-tls

Generate private key (.key)
# Key considerations for algorithm "RSA" ≥ 2048-bit
openssl genrsa -out server.key 2048

# Key considerations for algorithm "ECDSA" ≥ secp384r1
# List ECDSA the supported curves (openssl ecparam -list_curves)
@vanleantking
vanleantking / cookie_jar.go
Created October 26, 2018 10:43 — forked from rowland/cookie_jar.go
Go http client with cookie support