Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
No ways

Pham Tuan tuanpht

💭
No ways
View GitHub Profile
@tuanpht
tuanpht / local-vps-vagrant.md
Last active Jun 24, 2022
Create local VPS with vagrant
View local-vps-vagrant.md

Intro

A VPS is just a server machine (Ubuntu, CentOS,...) on the Internet which you can SSH into.

A local VPS is a VPS but running on your local machine thanks to Virtual Machine technology. It's very simple to create a VM thanks to Vagrant, so that you can use it to play with SSH, test deployment, test Ansible playbook,...

Setup

  1. Install VirtualBox
  2. Install Vagrant
  3. Create a virtual machine, for example: Ubuntu 20.04
View tmux-cheatsheet.markdown

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
View laravel-searchable-model-filter.md

Simple

$searchable = [
    'type',
    'date',
];

$petsQuery = Pet::where('user_id', '=', $request->user()->id);
// OR: $petsQuery = Pet::query(). For empty query
@tuanpht
tuanpht / php.code-snippets
Last active Jul 19, 2021
VS Code PHP snippet insert namespace, class, constructor
View php.code-snippets
{
"Insert namespace": {
"prefix": "name",
"body": ["namespace $1${TM_DIRECTORY/[\\/]/\\\\/g};", "$2"]
},
"Construct": {
"prefix": "cons",
"body": ["${1:public} function __construct()", "{$2\n}$0"]
},
"Class": {
@tuanpht
tuanpht / create-db.sql
Last active Oct 1, 2020
MySQL datetime vs timezone
View create-db.sql
# Create and insert data
CREATE TABLE `datetime_timestamp` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`datetime_value` datetime NOT NULL,
`timestamp_value` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`inputted_timezone` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
SET @@time_zone = 'SYSTEM';
@tuanpht
tuanpht / User.php
Last active Mar 30, 2020
Laravel Eloquent integration test model save with DB
View User.php
<?php
namespace App\Models;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\Hash;
class User extends Authenticatable
{
@tuanpht
tuanpht / RegisterRequest.php
Created Jul 24, 2019
Laravel Form Request Testing
View RegisterRequest.php
<?php
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rules\Unique;
class RegisterRequest extends FormRequest
{
const NAME_MAX_LENGTH = 255;
const EMAIL_MAX_LENGTH = 255;
const PASSWORD_MIN_LENGTH = 8;
@tuanpht
tuanpht / php-artisan-bash-completion.md
Last active Jun 20, 2022 — forked from jhoff/README.md
Bash-only Laravel Artisan tab auto-complete
View php-artisan-bash-completion.md

If you are an Oh-my-zsh user, see the Laravel 5 plugin

For the rest of us Bash users, all of the Laravel Artisan autocomplete solutions out there require installing a composer package to get a list of artisan commands. Turns out this isn't really necessary. Simply add the provided code in ~/.bash_profile ( or similarly sourced file ) and you'll get artisan command tab completes on any project on your system.

_artisan()
{
    local arg="${COMP_LINE#php }"

 case "$arg" in
@tuanpht
tuanpht / aws-ses.php
Last active May 30, 2022
PHP/Laravel AWS SES multiple emails multiple recipients
View aws-ses.php
<?php
use Aws\Ses\SesClient;
use Illuminate\Mail\Markdown;
// Create SES client
$ses = new SesClient([
'credentials' => [
'key' => config('services.ses.key'),
'secret' => config('services.ses.secret'),
],
@tuanpht
tuanpht / laravel-quickstart-project-docker.md
Created Jun 21, 2018 — forked from wataridori/laravel-quickstart-project-docker.md
Running Laravel Quick Start Project easily using Docker
View laravel-quickstart-project-docker.md
  • Install Docker
    • Docker for Ubuntu: https://docs.docker.com/engine/installation/linux/ubuntulinux/
      sudo apt-get update && apt-get install -y apt-transport-https ca-certificates
      sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
      
      // Open the /etc/apt/sources.list.d/docker.list and add the following line then save it
      // Ubuntu 14.04
      deb https://apt.dockerproject.org/repo ubuntu-trusty main
      

// Ubuntu 16.04