Skip to content

Instantly share code, notes, and snippets.

View yidas's full-sized avatar

Nick Tsai yidas

View GitHub Profile
<?php
$startTime = time();
$runSeconds = 5;
$rounds = 5;
$count = 0;
for ($i=0; $i<$rounds; $i++) {
while ((time()-$startTime) <= $runSeconds) {
serialize(['bar'=>'foo']);
$count ++;
@yidas
yidas / yii2-migrate-by-web-controller.md
Last active July 6, 2018 07:29
Yii2 Migrate command called by Web controller
public function actionMigrate()
{
    // Keep current application
    $oldApp = \Yii::$app;
    // Load Console Application config
    $config = require \Yii::getAlias('@app'). '/config/console.php';
    new \yii\console\Application($config);
    $result = \Yii::$app->runAction('migrate', ['migrationPath' => '@app/migrations/', 'interactive' => false]);
 // Revert application
@yidas
yidas / mysql-change-datadir.md
Created July 11, 2018 07:52
MySQL change data-dir for Ubuntu 16.04

MySQL change data-dir for Ubuntu 16.04

1. Change mysql.cnf

/etc/mysql/mysql.conf.d/mysql.cnf:

set datadir = /home/mysql
@yidas
yidas / yii2-actionError.md
Last active August 1, 2018 05:36
[Yii2] Yii2 sample code of Error Action handling such 404 errors

[Yii2] Yii2 sample code of Error Action handling such 404 errors

/**
 * Error action
 *
 * @return void
 */
public function actionError()
{
@yidas
yidas / yii2-mailer-set-layout.md
Last active August 1, 2018 05:40
[Yii2] Yii2 mailer set or disable layout template

[Yii2] Yii2 mailer set or disable layout template

Yii2 Mailer is extended by yii-mail-basemailer, which the compose() would render an mail view with default layout.

Set or Disable Mailer layout

$htmlLayout

[
@yidas
yidas / nginx-80-to-443.config.md
Last active November 22, 2018 08:25
Ngnix 80 to 443 Configuration
server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com; 
    return 301 https://$server_name$request_uri;
}

server {
 listen 443 ssl;
@yidas
yidas / PHP-DateTime-shiftMonths.md
Last active November 26, 2018 02:52
Shift a giving months from your input datetime with month based

Shift a giving months from your input datetime with month based

If the target month is smaller than the original month, the extra days will be discarded.

/**
 * Shift a giving months from your input datetime with month based
 * 
 * If the target month is smaller than the original month, the extra days will be discarded.
 * 
@yidas
yidas / sql-joins-diagram.md
Last active December 18, 2018 01:53
SQL Joins Explained Diagram
@yidas
yidas / yii2-app-basic-env-switch.md
Created January 3, 2019 03:50
Yii2 App Basic Environment Setting Switch for WEB & Console

Yii2 App Basic Environment Setting Switch for WEB & Console

Server Variable Solution

Add server variable condition for ./web/index.php & ./yii:

if (isset($_SERVER['APP_ENV']) && $_SERVER['APP_ENV']=='production') {
@yidas
yidas / openssl-dhparam.md
Last active January 15, 2019 03:13
[OpenSSL] Diffie–Hellman (DH) key exchange with at least 2048 bits