Skip to content

Instantly share code, notes, and snippets.

@khoatran
khoatran / setup-merge-diff-git.sh
Created March 22, 2017 10:39
Git setup merge and diff tool
git config --global --add merge.tool kdiff3
git config --global --add mergetool.kdiff3.path "absolute-path-to-the-kdiff-execution-file"
git config --global --add mergetool.kdiff3.trustExitCode false
git config --global --add diff.guitool kdiff3
git config --global --add difftool.kdiff3.path "absolute-path-to-the-kdiff-execution-file"
git config --global --add difftool.kdiff3.trustExitCode false
@khoatran
khoatran / ServiceProvider.php
Created February 15, 2017 15:35
Create OctoberCMS module
use App;
use October\Rain\Support\ModuleServiceProvider;
class ServiceProvider extends ModuleServiceProvider
{
/**
* Register the service provider.
*
* @return void
@khoatran
khoatran / CachableComponent.php
Last active June 24, 2020 09:12
OctoberCMS - CachableComponent
<?php
use Cache;
use Cms\Classes\ComponentBase;
abstract class CachableComponentBase extends ComponentBase
{
/**
* Build cache configuration which is an array: ['cachedKey' => 'The cache key value', 'cachedTimeInMinutes' => 'Cached time in minutes']
* @return mixed
@khoatran
khoatran / TextUtil.php
Last active April 17, 2024 10:21
Convert Vietnamese string to slug
<?php
class TextUtil {
public static function sanitize($title) {
$replacement = '-';
$map = array();
$quotedReplacement = preg_quote($replacement, '/');
$default = array(
'/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ|À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ|å/' => 'a',
'/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ|È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ|ë/' => 'e',
'/ì|í|ị|ỉ|ĩ|Ì|Í|Ị|Ỉ|Ĩ|î/' => 'i',
@khoatran
khoatran / remove-merged-branch.sh
Last active October 5, 2016 07:51
Git - delete redundant remote branches merged to master and keep important branches
git branch -r --merged | grep -v '\*\|master\|dev\|DTP-263' | sed 's/origin\///' | xargs -n 1 git push --delete origin
#The syntax to put branch to keep: \|branch-name
@khoatran
khoatran / website.conf
Created June 13, 2016 14:41
Nginx configuration for Wordpress - with fast cgi cache
server {
listen 80;
server_name website-domain.com;
root /data/apps/excitingthing;
index index.html index.htm index.php;
charset utf-8;
set $skip_cache 0;
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $skip_cache 1;
@khoatran
khoatran / set_wordpress_user_pass.sql
Created May 24, 2016 02:03
Set Wordpress user password by mysql
UPDATE wp_users SET user_pass = MD5('new_password') WHERE ID='id_of_the_user_to_reset_password' LIMIT 1;
@khoatran
khoatran / ssh_timeout_extend.sh
Created May 21, 2016 05:56
Extend SSH timeout
#It helps to add ClientAliveInterval of 60 mins into SSH config
sudo echo 'ClientAliveInterval 60' >> /etc/ssh/sshd_config
#Then, restart SSH
#Below is the command to restart ssh on Ubuntu based
sudo service ssh restart
#Other Linux distribution
sudo service sshd restart
@khoatran
khoatran / gitmove.sh
Last active May 20, 2016 08:52
Move a git repository to a new one - keep all history. manual.txt for the case you want to do manually. gitmove.sh is a Linux Bash that help you do faster
#!/bin/bash
echo "Please enter the source repository you want to move"
read SOURCE_REPOS
echo "Please enter the target repsitory that you want to move the repos"
read TARGET_REPOS
git clone --bare $SOURCE_REPOS
SOURCE_GIT_META_DIR=$(basename $SOURCE_REPOS)
cd $SOURCE_GIT_META_DIR && git push --mirror $TARGET_REPOS && cd .. && rm -rf $SOURCE_GIT_META_DIR
@khoatran
khoatran / analytic.js
Last active June 11, 2016 15:48
Google analytic tracking
var Analytic = (function(){
var module = {};
var trackEventOfElement = function(el) {
var category = el.attr('data-category');
var action = el.attr('data-action');
var label = el.attr('data-label');
var value = el.attr('data-value');
module.trackEvent(category, action, label, value);
};
var trackSocialOfElement = function(el) {