Skip to content

Instantly share code, notes, and snippets.

View hanafiah's full-sized avatar
🏠
Working from home

Muhamad Hanafiah Yahya hanafiah

🏠
Working from home
View GitHub Profile
@hanafiah
hanafiah / merah apple.php
Last active August 29, 2015 13:56
generate pivot table
<?php
try {
$db = new PDO('mysql:host=127.0.0.1;dbname=sampledb;charset=utf8', 'root', '');
} catch (PDOException $e) {
echo $e->getMessage();
}
$stmt = $db->query('SELECT DISTINCT(Sensor) FROM measure2');
$row_count = $stmt->rowCount();
IF a EQUAL TO b AND b EQUAL TO c THEN
PRINT 'The numbers are same';
ELSE
IF a SMALLER THAN b THEN
BEGIN
IF a SMALLER THAN c THEN
PRINT a;
ELSE
PRINT c;
END
@hanafiah
hanafiah / osx.terminal.color
Created October 24, 2013 09:40
my terminal color
function parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
RED="\[\033[31m\]"
YELLOW="\[\033[33m\]"
GREEN="\[\033[32m\]"
BLUE="\[\033[34m\]"
PURPLE="\[\033[35m\]"
CYAN="\[\035[36m\]"
NO_COLOUR="\[\033[0m\]"
<?php
//Answer #2
preg_match_all('/<a(?:\s+(?:href=[\'"](?P<href>.*?)[\'"]|title=[\'"](?P<title>.*?)["\']|\w+=[\'"](?P<other_attribute_goes_here>.*?)[\'"]))+/', $str, $match,PREG_PATTERN_ORDER);
print_r(array('href'=>$match['href'],'title'=>$match['title']));
@hanafiah
hanafiah / cronjob.list.sh
Created October 22, 2013 03:02
list all cronjob in server
for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done
@hanafiah
hanafiah / 3rdparty.cookies.php
Created October 22, 2013 03:00
header meta untuk 3rd party cookies
<?php
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
@hanafiah
hanafiah / paypal-ipn-validation.php
Created September 27, 2013 04:02
paypa ipn verification sample code
$post_string = 'cmd=_notify-validate&' . file_get_contents("php://input");
$ch = curl_init(PAYPAL_URL);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
private $zones = array(
'UM12' => '-12:00',
'UM11' => '-11:00',
'UM10' => '-10:00',
'UM95' => '-9:30',
'UM9' => '-9:00',
'UM8' => '-8:00',
'UM7' => '-7:00',
'UM6' => '-6:00',
'UM5' => '-5:00',
<?php
$destination_url = Array(
0 => 'http://www.google.com',
1 => 'http://www.google.com',
2 => 'http://www.google.com'
);
$split_percentage = Array(
0 => 50,
@hanafiah
hanafiah / jomniaga-opencart-success.tpl.php
Last active December 20, 2015 13:19
Part B Put this code to catalog/view/theme/default/template/common/success.tpl
<?php
/**
* Jomniaga Conversion code
*
* Put this file to catalog/view/theme/default/template/common/success.tpl
* before
* <?php echo $content_bottom; ?>
*
*/
if(isset($this->session->data['jomniaga'])){