Skip to content

Instantly share code, notes, and snippets.

View yidas's full-sized avatar

Nick Tsai yidas

View GitHub Profile
@yidas
yidas / js-encode-decode.md
Last active April 6, 2022 15:26
JavaScript HTML Entities Encode & Decode
@victorbstan
victorbstan / php_object_to_array.php
Created December 17, 2010 04:18
recursively cast a PHP object to array
<?php
/*
This function saved my life.
found on: http://www.sitepoint.com/forums//showthread.php?t=438748
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);
@bryanhunter
bryanhunter / MonokaiSW.md
Last active October 15, 2021 08:12
Mapping colors of the Monokai color scheme to their nearest Sherwin-Williams paint color
@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
$ php some-bench.php
strtotime: 0.15609812736511
datetime: 0.31521701812744
datetime without instanciation: 0.11794400215149
custom: 0.70522284507751