Skip to content

Instantly share code, notes, and snippets.

View hungthai1401's full-sized avatar
:octocat:
Available For Hire

Thai Nguyen Hung hungthai1401

:octocat:
Available For Hire
View GitHub Profile
@hungthai1401
hungthai1401 / rvm.txt
Last active November 2, 2018 10:06
Install ruby
Install rvm:
1. $gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
2. curl -sSL https://get.rvm.io -o rvm.sh
3. source ~/.rvm/scripts/rvm
4. rvm install ruby --default
@hungthai1401
hungthai1401 / delete_slack_messages.js
Last active November 2, 2018 10:06
Delete all messages in a Slack channel
var https = require('https');
// CONFIGURATION #######################################################################################################
var token = 'SLACK TOKEN';
var channel = 'CHANNEL ID';
var privateChannel = false;
var delay = 300; // delay between delete operations in millisecond
// GLOBALS #############################################################################################################
@hungthai1401
hungthai1401 / format.txt
Last active September 18, 2018 14:14
Format datetime
Format datetime by Carbon:
1. setlocale(LC_TIME, 'ja_JP.utf8');
2. $value->formatLocalized('%Y/%-m/%d (%a) %H:%M') (Ex: 2018/4/15 (日) 20:47)
Note:
- Month without leading zero: %-m
@hungthai1401
hungthai1401 / request.txt
Created October 4, 2018 09:36
Form request return json
use Illuminate\Validation\ValidationException;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;
/**
* Handle a failed validation attempt.
*
* @param \Illuminate\Contracts\Validation\Validator $validator
* @return void
*
@hungthai1401
hungthai1401 / installing-node-with-nvm.md
Created October 11, 2018 02:02 — forked from d2s/installing-node-with-nvm.md
Installing Node.js for Linux & macOS with nvm
@hungthai1401
hungthai1401 / swap.js
Created October 26, 2018 06:42
Swap value of variables using destructuring assignment
let a = 10, b = 12;
[a, b] = [b, a];
@hungthai1401
hungthai1401 / BackUpDatabase.php
Created November 2, 2018 09:47
Laravel command backup, restore postgresql database
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
class BackUpDatabase extends Command
{
@hungthai1401
hungthai1401 / phpstorm-cs-fixer.md
Created January 10, 2019 04:43 — forked from nienkedekker/phpstorm-cs-fixer.md
Set up PHP-CS-Fixer in PHPStorm

Use PHP-CS-Fixer in PHPStorm

  • Install PHP-CS-Fixer on your local machine according to these instructions: https://github.com/FriendsOfPHP/PHP-CS-Fixer
  • Open PHPStorm, Preferences > Tools > External Tools and enter these values: img
  • Program, edit to match your path where PHP-CS-Fixer lives: /.composer/vendor/friendsofphp/php-cs-fixer/php-cs-fixer
  • Parameters: --rules=@PSR2 --verbose fix $FileDir$/$FileName$. Note that previous verions of PHP-CS-Fixer used --levels instead of --rules.
  • Working directory: $ProjectFileDir$

Click OK and Apply. Now we'll set up a shortcut.

  • Go to Preferences > Keymap and search for "PHP Fixer" (or whatever name you gave it). Add whatever shortcut you like, I'm using ctrl + cmd + ]:
$ cd ~
$ sudo curl -sS https://getcomposer.org/installer | sudo php
$ sudo mv composer.phar /usr/local/bin/composer
$ sudo ln -s /usr/local/bin/composer /usr/bin/composer
then you can run
$ sudo composer install
@hungthai1401
hungthai1401 / simplehttp.service
Created August 23, 2019 09:09 — forked from funzoneq/simplehttp.service
A systemd file for a python SimpleHTTPServer
[Unit]
Description=Job that runs the python SimpleHTTPServer daemon
Documentation=man:SimpleHTTPServer(1)
[Service]
Type=simple
WorkingDirectory=/tmp/letsencrypt
ExecStart=/usr/bin/python -m SimpleHTTPServer 80 &
ExecStop=/bin/kill `/bin/ps aux | /bin/grep SimpleHTTPServer | /bin/grep -v grep | /usr/bin/awk '{ print $2 }'`