Skip to content

Instantly share code, notes, and snippets.

View zmiftah's full-sized avatar
💭
Waiting List ...

Zein Miftah zmiftah

💭
Waiting List ...
  • West Java, Indonesia
View GitHub Profile
@zmiftah
zmiftah / sql_postgres_pivot_tablefunc.sql
Created June 10, 2015 08:22
Postgres Pivot tablefunc
-- 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;
@zmiftah
zmiftah / install_composer_on_ubuntu.txt
Created March 31, 2015 11:00
How to Install Composer on Ubuntu 14.04
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
@zmiftah
zmiftah / date_class.php
Last active August 29, 2015 14:17
DateTime and DateInterval Function
<?php
function getDateFromNow($interval='P1D', $direction='add') {
$currentDate = new DateTime;
$intervalDate = new DateInterval($interval);
if ($direction == 'sub') {
$resultDate = $currentDate->sub($intervalDate);
} else {
<?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 = '';
@zmiftah
zmiftah / cmd_kill_process_ssh.sh
Created March 23, 2015 10:41
Linux Command : Kill Process SSH
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
@zmiftah
zmiftah / function_traverse_hierarcy_data.php
Created March 12, 2015 09:25
How to Create Treelike Structure
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'];
@zmiftah
zmiftah / yii_clientscript_heredoc.php
Created March 12, 2015 09:20
Use Heredoc to Save Script and Register it.
$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);
@zmiftah
zmiftah / enumerable_data.php
Last active August 29, 2015 14:16
Create Enumerable Class as Array
<?php
class EnumerableData implements Iterator, Countable
{
private $position = 0;private $count = 0;
private $keys = array();
private $vars = array();
public function __construct()
{
$this->rewind();
@zmiftah
zmiftah / postgre_snippets.sql
Last active July 6, 2017 04:21
Collection of Snippet from Postgres Query
-- 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 --//
<?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();