Skip to content

Instantly share code, notes, and snippets.

var d = new Date();
var mysqlDate = d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds(); // 2001-03-10 17:16:18 (the MySQL DATETIME format)
@khoand0000
khoand0000 / NamingConventionConverter.php
Created October 3, 2014 13:49
convert naming convention (PascalCased, camelCased, with_underscores) to each other
<?php
class NamingConventionConverter {
/**
* convert camelCasedString or PascalCasedString to underscores_string
* ref: http://stackoverflow.com/questions/1993721/how-to-convert-camelcase-to-camel-case
* @param string $word camelCasedString or PascalCasedString
* @return string underscores_string
*/
public static function camel2Underscores($word) {
_
@khoand0000
khoand0000 / should.php
Created November 8, 2014 13:45
should to do this to help phpStorm recognize variable
/* @var $this yii\web\View */
@khoand0000
khoand0000 / javascript.js
Created November 8, 2014 15:09
javascript
// redirect url
window.location.assign(url);
@khoand0000
khoand0000 / array.php
Last active August 29, 2015 14:09
php
// use + operator when plus 2 array instead of array_merge because array_merge re-index
['' => ''] + [0, 1, 2]
@khoand0000
khoand0000 / composer-wordpress.json
Last active August 29, 2015 14:09
composer - packages.json: create project from packages.json (packages.json contains location of source (.zip), .zip contains composer.json describe information of module) composer create-project --repository-url packages.json acme/hello-world
/*
ref: http://roots.io/using-composer-with-wordpress/
*/
{
"repositories": [
{
"type": "package",
"package": {
"name": "wordpress",
"type": "webroot",
@khoand0000
khoand0000 / angular-convention.md
Last active December 7, 2015 11:21
Everything about angular: - conventions - rules - snippets

Angular uses spinal-case for its custom attributes and camelCase for the corresponding directives which implement them

best practices: https://github.com/johnpapa/angular-styleguide

Rules:

  • Each feature directory (https://github.com/johnpapa/angular-styleguide#style-y121) also contains feature.shared.js file (customer.shared.js, supplier.shared.js) to share code between another files in same feature directory. If code (functions: calculating formular, ...) is used between feature directory, put it to UI service.
  • component directory contains directives and modal or template html (<script id="error-list.html" type="text/ng-template"></script> (maybe separating it to templates directory. I haven't decided it)
  • Services just take care model (processing received data from server before return to controller), don’t do anything relates to ui (html)
  • Exception: UI service is using to share code, shared data relates to UI (data is used to be exchanged between views, directives, cont
@khoand0000
khoand0000 / controller.php
Last active August 29, 2015 14:10
cakephp
<?php
class PostsController extends AppController {
public $uses = array('Post', 'Recipe', 'User'); // use more models: Recipe, User
public $helpers = array('Js');
public $components = array('RequestHandler');
public function my_action() {
$this->render('custom_file'); // render app/View/Posts/custom_file.ctp instead of app/View/Posts/my_action.ctp
// Render the element in /View/Elements/ajaxreturn.ctp
$this->render('/Elements/ajaxreturn');
$start = microtime(true);
// your code
$end = microtime(true);
echo ($end - $start).' seconds';