Skip to content

Instantly share code, notes, and snippets.

View dilab's full-sized avatar

Xu Ding dilab

View GitHub Profile
@dilab
dilab / gist:6247f5d6520f72ab617434e2e9065fbf
Created April 13, 2021 03:55
Github current issue titles
var issues = $$('.markdown-title');
var content = "";
for (i in issues) {
content = content + "+ User: fix - " +issues[i].text + "\n";
}
window.prompt ("Copy to clipboard: Ctrl+C, Enter", content);
@dilab
dilab / gist:36e3097a9ce1041aae334a52f17c25b4
Created August 2, 2017 03:30
Fat controller, fat service and fat entity
## Pros and Cons of fat controller
### Pros
+ Fast dev time, no extra layer
### Cons
+ No reusable code for different interfaces (API, CLI and Controller)
## Pros and Cons of fat service class
@dilab
dilab / test.ctp
Last active August 30, 2016 08:44
<?= $this->Form->create($entry); ?>
<?=
$this->Form->input('emy_contact_no.code', [
'options' => ['1' => 1, '2' => 2],
'empty' => 'Select',
'class' => 'form-control',
'label' => false,
])
?>
<?php
namespace App\Controller;
use Cake\Event\Event;
use Cake\ORM\TableRegistry;
use Cake\Utility\Hash;
class RegistrationController extends AppController
{
@dilab
dilab / key_generator
Created July 19, 2016 05:49
Generate unique names
<?php
class KeyGenerator
{
public static function fromLabels(array $labels)
{
if (empty($labels)) {
return [];
}
@dilab
dilab / sql_backup.sh
Created June 12, 2016 13:47 — forked from niraj-shah/sql_backup.sh
Amazon S3 Backup Script for MySQL Databases
#!/bin/bash
# Shell script to backup MySql database
# CONFIG - Only edit the below lines to setup the script
# ===============================
MyUSER="root" # USERNAME
MyPASS="password" # PASSWORD
MyHOST="localhost" # Hostname
return array_map(function ($c, $serializedTicket) {
$ticket = unserialize($serializedTicket);
return [
'id' => $ticket->get('id'),
'name' => $ticket->get('name'),
'amt' => $this->toDollarFormat($ticket->get('price')->toCent()),
'qty' => $c
];
@dilab
dilab / array_unique_associative
Last active December 23, 2015 08:40
Array unique for associative array
array_map('unserialize', array_unique(array_map('serialize', $input)));
$oDateNow = new DateTime();
$oDateBirth = new DateTime($sDateBirth);
$age = $oDateNow->diff($oDateBirth)->y;
// its take day into consideration