Skip to content

Instantly share code, notes, and snippets.

View dilab's full-sized avatar

Xu Ding dilab

View GitHub Profile
@dilab
dilab / phing-remote-pull
Created April 10, 2014 07:14
This phing snippet will help you run "git pull" on remote server from your local dev machine
<?xml version="1.0" encoding="UTF-8" ?>
<project name="Awesome Application" default="update">
<target name="update" description="">
<property name="username" value="" />
<property name="hostname" value="" />
<property name="public_path" value="/srv/www/your-app/public_html" />
<exec outputProperty="result"
command="ssh ${username}@${hostname} 'cd ${public_path}; git pull;'" />
@dilab
dilab / implode_smart.php
Last active September 6, 2015 03:36
Implode array, but smart enough to filter out empty values.
function implode_filter($glue , $pieces) {
return implode($glue, array_filter($pieces));
}
@dilab
dilab / format_array.hp
Created September 6, 2015 03:36
Convert array to new format, but with the same data
$oldFormat = array(
'male' => 'Male',
'female' => 'Female'
);
$newFormat = array_map(function($value, $label) {
return array(
'label' => $label,
'value' => $value,
);
$oDateNow = new DateTime();
$oDateBirth = new DateTime($sDateBirth);
$age = $oDateNow->diff($oDateBirth)->y;
// its take day into consideration
@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)));
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 / 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
@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 [];
}
<?php
namespace App\Controller;
use Cake\Event\Event;
use Cake\ORM\TableRegistry;
use Cake\Utility\Hash;
class RegistrationController extends AppController
{
@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,
])
?>