Skip to content

Instantly share code, notes, and snippets.

View thephucit's full-sized avatar

Thế Phúc thephucit

View GitHub Profile
@thephucit
thephucit / laravel-tips.md
Created February 15, 2019 02:34
một vài tips hay trong laravel

#Order by Mutator

function getFullNameAttribute()
{
    return $this->attributes['first_name'] . ' ' . $this->attributes['last_name'];
}

$clients = Client::get()->sortBy('full_name'); // works!

#Default ordering in global scope

@thephucit
thephucit / docker-compose.yml
Created February 15, 2019 10:00
config docker composer: php, nginx, postgres, mysql, etc ...
version: "3"
services:
web:
image: webdevops/php-nginx:7.1
ports:
- "8082:80"
volumes:
- /Users/tunlookup/Documents/cmerp:/app # change path to your project
environment:
- PHP_DEBUGGER=xdebug
@thephucit
thephucit / bash.sh
Created February 21, 2019 08:46
Run PostgreSQL on docker ubuntu server
sudo apt-get install docker.io
postgres=$(sudo docker run -e POSTGRES_PASSWORD=postgres -d -p 5432:5432 postgres)
sudo docker commit $postgres kinto-db
kintodb=$(sudo docker run -e POSTGRES_PASSWORD=postgres -d -p 5432:5432 kinto-db)
# ... Use it!
sudo docker stop $kintodb
@thephucit
thephucit / ErrorCatch.php
Created June 6, 2019 07:25
customize error for graphql
<?php namespace Name\Graphql\Classes;
use GraphQL\Error\Error;
use Rebing\GraphQL\Error\ValidationError;
use Rebing\GraphQL\GraphQL;
class ErrorCatch extends GraphQL
{
public static function formatError(Error $e)
{
@thephucit
thephucit / RC4.php
Created June 6, 2019 07:26
RC4 generate web token
<?php namespace Name\Graphql\Classes;
use Exception;
class RC4
{
const EXP_DAY = 1;
public static function encode($array, $key = null)
{
@thephucit
thephucit / index.php
Created June 21, 2019 07:55
some helper function
<?php
/**
* detect hastag from string
*
* @param [string] $string
* @return [array]
*/
public function detectHastag($string)
{
function parseVideo (url) {
// - Supported YouTube URL formats:
// - http://www.youtube.com/watch?v=My2FRPA3Gf8
// - http://youtu.be/My2FRPA3Gf8
// - https://youtube.googleapis.com/v/My2FRPA3Gf8
// - Supported Vimeo URL formats:
// - http://vimeo.com/25451551
// - http://player.vimeo.com/video/25451551
// - Also supports relative URLs:
// - //player.vimeo.com/video/25451551
function parseVideo (url) {
// - Supported YouTube URL formats:
// - http://www.youtube.com/watch?v=My2FRPA3Gf8
// - http://youtu.be/My2FRPA3Gf8
// - https://youtube.googleapis.com/v/My2FRPA3Gf8
// - Supported Vimeo URL formats:
// - http://vimeo.com/25451551
// - http://player.vimeo.com/video/25451551
// - Also supports relative URLs:
// - //player.vimeo.com/video/25451551
@thephucit
thephucit / helper.js
Created August 11, 2019 10:34
detect content including youtube, vimeo, dailymotion OR normal link
/**
* detect content including youtube, vimeo, dailymotion OR normal link
*
* @param {String} string
* @param {Number} height
* @return {String}
*/
link: (string, height = 345) => {
let getInfo = (url) => {
url.match(/(http:|https:|)\/\/(player.|www.)?(vimeo\.com|youtu(be\.com|\.be|be\.googleapis\.com)|dailymotion.com)\/(video\/|embed\/|watch\?v=|v\/)?([A-Za-z0-9._%-]*)(&\S+)?/)
var emojis = [
'😄','😃','😀','😊','☺','😉','😍','😘','😚','😗','😙','😜','😝','😛','😳','😁','😔','😌','😒','😞','😣','😢','😂','😭','😪','😥','😰','😅','😓','😩','😫','😨','😱','😠','😡','😤','😖','😆','😋','😷','😎','😴','😵','😲','😟','😦','😧','😈','👿','😮','😬','😐','😕','😯','😶','😇','😏','😑','👲','👳','👮','👷','💂','👶','👦','👧','👨','👩','👴','👵','👱','👼','👸','😺','😸','😻','😽','😼','🙀','😿','😹','😾','👹','👺','🙈','🙉','🙊','💀','👽','💩','🔥','✨','🌟','💫','💥','💢','💦','💧','💤','💨','👂','👀','👃','👅','👄','👍','👎','👌','👊','✊','✌','👋','✋','👐','👆','👇','👉','👈','🙌','🙏','☝','👏','💪','🚶','🏃','💃','👫','👪','👬','👭','💏','💑','👯','🙆','🙅','💁','🙋','💆','💇','💅','👰','🙎','🙍','🙇','🎩','👑','👒','👟','👞','👡','👠','👢','👕','👔','👚','👗','🎽','👖','👘','👙','💼','👜','👝','👛','👓','🎀','🌂','💄','💛','💙','💜','💚','❤','💔','💗','💓','💕','💖','💞','💘','💌','💋','💍','💎','👤','👥','💬','👣','💭','🐶','🐺','🐱','🐭','🐹','🐰','🐸','🐯','🐨','🐻','🐷','🐽','🐮','🐗','🐵','🐒','🐴','🐑','🐘','🐼','🐧','🐦','🐤','🐥','🐣','🐔','🐍','🐢','🐛','🐝','🐜','🐞','🐌','🐙','🐚','🐠','🐟','🐬','🐳','🐋','🐄','🐏','🐀','🐃','🐅','🐇','🐉','🐎','🐐','🐓','🐕','🐖','🐁','🐂','🐲','🐡','🐊','🐫','🐪','🐆','🐈','🐩','🐾',