This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Enable tablefunc | |
CREATE EXTENSION tablefunc; | |
-- Original Query Data | |
SELECT generate_series AS date, | |
b.desc AS TYPE, | |
(random() * 10000 + 1)::int AS val | |
FROM generate_series((now() - '100 days'::interval)::date, now()::date, '1 day'::interval), | |
(SELECT unnest(ARRAY['OSX', 'Windows', 'Linux']) AS DESC) b; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Download curl -sS https://getcomposer.org/installer | php | |
2. Install https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx | |
- mv composer.phar /usr/local/bin/composer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getDateFromNow($interval='P1D', $direction='add') { | |
$currentDate = new DateTime; | |
$intervalDate = new DateInterval($interval); | |
if ($direction == 'sub') { | |
$resultDate = $currentDate->sub($intervalDate); | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Assuming a POST to this script in form of: | |
// request_forwarder?url=url_name | |
// | |
// This will convert a client side AJAX request to a server side PHP curl, | |
// thus eleminating worries of cross-site scripting and having to abide by | |
// cross-origin-request-sharing (CORS) settings on the end server. | |
$url = $_GET['url']; | |
$fields_string = ''; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ps -ax | grep ssh | |
/* Result | |
886 pts/3 S+ 0:00 grep --color=auto ssh | |
1016 ? Ss 0:00 /usr/sbin/sshd -D | |
3783 pts/5 S 0:37 ssh -x -a -oClearAllForwardings=yes -2 [email protected] -s sftp | |
3835 ? Ssl 1:05 sshfs [email protected]:/home/project /mnt/pkpu_pro | |
*/ | |
sudo kill -9 886 1016 3783 3835 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected function traverseData($programs, $parentId=0) | |
{ | |
$data = array(); | |
foreach ($programs as $id => $program) { | |
if ($program['parent'] == $parentId) { | |
$nodes = $this->traverseData($programs, $program['id']); | |
$obj = new StdClass; | |
$obj->text = $program['name']; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$script = <<<EOB | |
var data = :data; | |
$('#treeview').treeview({data: %s}); | |
$('#treeview').on('nodeSelected', function(e, node){/* */}); | |
EOB; | |
$script = sprintf($script, json_encode($treeview)); | |
Yii::app()->clientScript->registerScript('loadTree', $script, CClientScript::POS_READY); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class EnumerableData implements Iterator, Countable | |
{ | |
private $position = 0;private $count = 0; | |
private $keys = array(); | |
private $vars = array(); | |
public function __construct() | |
{ | |
$this->rewind(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Grant For Schema | |
GRANT ALL PRIVILEGES ON SCHEMA pdg TO project1; | |
-- Grant For Table | |
GRANT ALL PRIVILEGES ON TABLE pdg.proposal TO project1; | |
-- Grant For Sequence | |
GRANT USAGE, SELECT ON SEQUENCE pdg.proposal_id_seq TO project1; | |
-- Grant For View | |
GRANT SELECT ON pdg.vw_program_hierarchy TO project1; | |
-- //-- Source: http://www.postgresql.org/docs/8.3/static/sql-grant.html --// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Calculate a precise time difference. | |
* @param string $start result of microtime() | |
* @param string $end result of microtime(); if NULL/FALSE/0/'' then it's now | |
* @return flat difference in seconds, calculated with minimum precision loss | |
*/ | |
function microtime_diff($start, $end = null) { | |
if (!$end) $end = microtime(); |