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 / 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
<?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 / 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\]"
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 / 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();
<!DOCTYPE html>
<html>
<head>
<title>Geolocation</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
<script type="text/javascript">
var loc = window.location.hash.substr(1);
if (loc == 'bke01') {
context.font = '20px Arial';
context.strokeText('BKE01', 70, 330);
context.beginPath();
context.rect(50, 300, 100, 50);
context.fillStyle = 'white';
context.lineWidth = 2;
context.strokeStyle = 'red';
<script type="text/javascript">
var loc = window.location.hash.substr(1);
//start position
context.beginPath();
context.arc(190, 450, 10, 0, 2 * Math.PI, false);
context.fillStyle = 'white';
context.lineWidth = 2;
context.strokeStyle = 'red';
context.stroke();
<?php
$host = 'localhost';
$dbname = 'tutorial_pdo';
$user = 'root';
$pass = '';
try {
//$dbh , database handler aka db handler
$dbh = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
CREATE TABLE users (
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(20) NOT NULL,
full_name VARCHAR(80) NOT NULL,
password VARCHAR(40) NOT NULL,
salt VARCHAR(40) DEFAULT NULL,
email VARCHAR(80) NOT NULL
)
ENGINE InnoDB;