Skip to content

Instantly share code, notes, and snippets.

@khoatran
khoatran / configuration_doc.md
Last active May 5, 2016 07:52
Multiple SSH Keys settings for different git account

Multiple SSH Keys settings for different git account

Create different public key

Create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"
@khoatran
khoatran / MenuBuilder.php
Last active May 11, 2016 05:13
[Laravel] MenuBuilder to build menu view-object from Laravel config
<?php
class MenuBuilder
{
public static function buildMenuViewObjectFromConfig($configKey) {
$result = [];
$menu = config($configKey);
foreach ($menu as $mainMenuItem) {
$menuViewObject = self::buildMenuViewObject($mainMenuItem);
if(!empty($menuViewObject)) {
@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 / CustomEloquentModel.php
Last active May 20, 2016 09:08
A custom Eloquent model from Jenssegers\Mongodb to solve serialisation issue of new MongoDriver
<?php
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
use LaunchCMS\Utils\SerializeUtil;
abstract class LaunchEloquentModel extends Eloquent implements \Serializable
{
protected $connection = 'mongodb';
protected $array_fields = [];
public function serialize()
{
@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 / 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 / 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) {
@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 / 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 / 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