Skip to content

Instantly share code, notes, and snippets.

Khoa Tran khoatran

Block or report user

Report or block khoatran

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@khoatran
khoatran / PhoneNumber.java
Last active May 13, 2019
Liskov - violation - hashCode example
View PhoneNumber.java
/*
* From Effective Java book - 2nd Edition - Author: Joshua Bloch
*/
public final class PhoneNumber {
private final short areaCode;
private final short prefix;
private final short lineNumber;
public PhoneNumber(int areaCode, int prefix,
int lineNumber) {
rangeCheck(areaCode, 999, "area code");
@khoatran
khoatran / parse-json.sh
Created Apr 3, 2019
Bash parse JSON key
View parse-json.sh
#!/bin/bash
function jsonValue() {
KEY=$1
num=$2
awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'$KEY'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p
}
KEY_TO_PARSE=$(curl -s -X GET "JSON_URL" | jsonValue KEY_TO_PARSE 1)
echo $KEY_TO_PARSE
@khoatran
khoatran / git-log-with-time.sh
Created Mar 5, 2019
Git log one line with time
View git-log-with-time.sh
git log --oneline --pretty=format:"%h%x09%an%x09%ad%x09%s"
@khoatran
khoatran / Plugin.php
Last active Jan 24, 2019
OctoberCMS add fields under secondary tabs
View Plugin.php
<?php
class Plugin extends PluginBase
{
public function boot()
{
parent::boot();
$this->extendRainlabPost();
}
protected function extendRainlabPost() {
@khoatran
khoatran / switch-php-version-ubuntu.sh
Created Apr 10, 2018
Switch between PHP version on Ubuntu
View switch-php-version-ubuntu.sh
sudo update-alternatives --set php /usr/bin/php7.1
sudo update-alternatives --set phar /usr/bin/phar7.1
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.1
sudo update-alternatives --set phpize /usr/bin/phpize7.1
sudo update-alternatives --set php-config /usr/bin/php-config7.1
@khoatran
khoatran / ModelNeedToValidate.php
Created Jan 2, 2018
OctoberCMS model validation
View ModelNeedToValidate.php
<?php
use Carbon\Carbon;
use Model;
use Validator;
/**
* Model
*/
class WorkingSchedule extends Model
{
@khoatran
khoatran / october-deployment.sh
Last active Nov 3, 2018
Bamboo deployment script
View october-deployment.sh
export DEPLOYMENT_FOLDER=/deployment-folder
export RELEASE_ROOT_FOLDER=$DEPLOYMENT_FOLDER/releases
export RELEASE_FOLDER=$DEPLOYMENT_FOLDER/releases/intermediate
cd $DEPLOYMENT_FOLDER/build
tar -xvf artifact.tar
rm -rf artifact.tar
cd $DEPLOYMENT_FOLDER
shopt -s dotglob
# Unzip and copy all files in artifact into the release folder
mkdir $RELEASE_FOLDER
@khoatran
khoatran / laravel-echo-fix-sqlite3.sh
Created Oct 3, 2017
Fix Cannot find module node_sqlite3.node when running Laravel Echo Server
View laravel-echo-fix-sqlite3.sh
cd /usr/local/lib/node_modules/laravel-echo-server/
npm install sqlite3 --save
View upgrade-node.sh
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo ln -sf /usr/local/n/versions/node/<version>/bin/node /usr/bin/node
sudo ln -sf /usr/local/n/versions/node/<version>/bin/npm /usr/local/bin/npm
@khoatran
khoatran / gist:75da6485ec690662e7f77e1952d89b5d
Created Oct 3, 2017
Fix Laravel mix strange issue spawn webpack.js ENOENT
View gist:75da6485ec690662e7f77e1952d89b5d
rm -rf node_modules
rm package-lock.json yarn.lock
npm cache clear --force
npm install
You can’t perform that action at this time.