Skip to content

Instantly share code, notes, and snippets.


Nick Tsai yidas

View GitHub Profile
View result.txt
$ php some-bench.php
strtotime: 0.15609812736511
datetime: 0.31521701812744
datetime without instanciation: 0.11794400215149
custom: 0.70522284507751
yidas /
Last active Jul 6, 2018
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 /
Last active Nov 17, 2019
Laravel Server Configuration for Nginx & Apache (Subdirectory)

Laravel Server Configuration for Nginx & Apache (Subdirectory)

It's easy to configurate a Laravel server site with directory protection:

Laravel Web Server Configuration

Sub Directory Site Application

Laravel smartly detects the current base url so that you don't need to set the base url for subdirectoy:

bryanhunter /
Last active Oct 15, 2021
Mapping colors of the Monokai color scheme to their nearest Sherwin-Williams paint color
victorbstan / php_object_to_array.php
Created Dec 17, 2010
recursively cast a PHP object to array
View php_object_to_array.php
This function saved my life.
found on:
by: crvandyke
It takes an object, and when all else if/else/recursive functions fail to convert the object into an associative array, this one goes for the kill. Who would'a thunk it?!
$array = json_decode(json_encode($object), true);
yidas /
Last active Apr 6, 2022
JavaScript HTML Entities Encode & Decode
yidas /
Last active Aug 3, 2022
Codeigniter 3 server configuration for Nginx & Apache

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:

jaxbot / gist:5748513
Created Jun 10, 2013
Block nginx from serving .git directories
View gist:5748513
location ~ /\.git {
deny all;
# or, all . directories/files in general (including .htaccess, etc)
location ~ /\. {
deny all;
yidas /
Last active Sep 13, 2022
Certificate(CSR) configuration file

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 /
Last active Sep 15, 2022
JavaScript nl2br & br2nl functions

JavaScript nl2br & br2nl functions

The exchange of new line & br HTML tag could refer to PHP - nl2br() function, which uses to inserts HTML line breaks before all newlines in a string.

These JavaScript functions consider whether to use insert or replace to handle the swap.