Skip to content

Instantly share code, notes, and snippets.

Avatar

Nick Tsai yidas

View GitHub Profile
View VS Code PHP Snippets
{
/*
// Place your snippets for PHP here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"Print to console": {
"prefix": "log",
"body": [
View PHP CLI Benchmark script
<?php
$startTime = time();
$runSeconds = 5;
$rounds = 5;
$count = 0;
for ($i=0; $i<$rounds; $i++) {
while ((time()-$startTime) <= $runSeconds) {
serialize(['bar'=>'foo']);
$count ++;
View Laravel 5 Resource Controller Template
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PhotoController extends Controller
{
/**
* Display a listing of the resource.
@yidas
yidas / yii2-migrate-by-web-controller.md
Last active Jul 6, 2018
Yii2 Migrate command called by Web controller
View yii2-migrate-by-web-controller.md
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 / codeigniter-set-env-for-cli.md
Last active Mar 27, 2020
Codeigniter - Set environment when running in CLI mode
View codeigniter-set-env-for-cli.md

Codeigniter - Set environment when running in CLI mode

There are some ways to set environment when running in CLI mode for Codeigniter 3:

Set Var in Command Way:

$ CI_ENV="production" php index.php welcome/index
@yidas
yidas / yii2-mailer-set-layout.md
Last active Aug 1, 2018
[Yii2] Yii2 mailer set or disable layout template
View yii2-mailer-set-layout.md

[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 / codeiginter-server-config.md
Last active Nov 11, 2021
Codeigniter 3 server configuration for Nginx & Apache
View codeiginter-server-config.md

Codeigniter 3 server configuration for Nginx & Apache

Web Server Site Configuration

Recommended Apache Configuration

Use the following configuration in Apache's httpd.conf file or within a virtual host configuration. Note that you should set DocumentRoot and ServerName fit to your environment:

@yidas
yidas / csr.conf.md
Last active Nov 2, 2021
Certificate(CSR) configuration file
View csr.conf.md

Openssl commands:

openssl genrsa -out self-ssl.key
openssl req -new -key self-ssl.key -out self-ssl.csr -config csr.conf
openssl x509 -req -days 365 -in self-ssl.csr -signkey self-ssl.key -out self-ssl.crt -extensions req_ext -extfile csr.conf

Sign from Root CA: openssl x509 -req -days 365 -extensions req_ext -extfile csr.conf -CA RootCA.crt -CAkey RootCA.key -in self-ssl.csr -out self-ssl.crt

@yidas
yidas / nginx-80-to-443.config.md
Last active Nov 22, 2018
Ngnix 80 to 443 Configuration
View nginx-80-to-443.config.md
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 / composer-install-vcs.md
Last active Oct 17, 2021
Composer install package via VCS such as GitLab (Private package requirement)
View composer-install-vcs.md

Composer install package via VCS such as GitLab

(Private package requirement)

1. Create composer.json:

{
    "repositories": [                                             
        {                                                         
            "type": "vcs",