Skip to content

Instantly share code, notes, and snippets.

View hengkiardo's full-sized avatar

Hengki Sihombing hengkiardo

  • Jakarta, Indonesia
View GitHub Profile
@hengkiardo
hengkiardo / gist:4023845
Created November 6, 2012 10:10
Example of scrollbar customization (works in Webkit only)
::-webkit-scrollbar {
width: 12px;
}
::-webkit-scrollbar-track {
background: none;
}
::-webkit-scrollbar-thumb {
background: -webkit-linear-gradient(left, #547c90, #002640);
@hengkiardo
hengkiardo / gist:4023855
Created November 6, 2012 10:13
Create image data URIs (base64) using PHP
// A few settings
$image = 'cricci.jpg';
// Read image path, convert to base64 encoding
$imageData = base64_encode(file_get_contents($image));
// Format the image SRC: data:{mime};base64,{data};
$src = 'data: '.mime_content_type($image).';base64,'.$imageData;
// Echo out a sample image
@hengkiardo
hengkiardo / gist:4023868
Created November 6, 2012 10:16
Get latitude and longitude from an adress
function getLatLong($address){
if (!is_string($address))die("All Addresses must be passed as a string");
$_url = sprintf('http://maps.google.com/maps?output=js&q=%s',rawurlencode($address));
$_result = false;
if($_result = file_get_contents($_url)) {
if(strpos($_result,'errortips') > 1 || strpos($_result,'Did you mean:') !== false) return false;
preg_match('!center:\s*{lat:\s*(-?\d+\.\d+),lng:\s*(-?\d+\.\d+)}!U', $_result, $_match);
$_coords['lat'] = $_match[1];
$_coords['long'] = $_match[2];
}
@hengkiardo
hengkiardo / gist:4023880
Created November 6, 2012 10:19
Download and save images from a page using cURL
function getImages($html) {
$matches = array();
$regex = '~http://somedomain.com/images/(.*?)\.jpg~i';
preg_match_all($regex, $html, $matches);
foreach ($matches[1] as $img) {
saveImg($img);
}
}
function saveImg($name) {
@hengkiardo
hengkiardo / gzip_footer.php
Created November 6, 2012 10:24
Use GZip compression on your PHP files
@hengkiardo
hengkiardo / iphone.css
Created November 19, 2012 04:43
Single Element iPhone 5 using CSS3
body {background: url(http://subtlepatterns.com/patterns/classy_fabric.png)}
/* First, we'll make the body. After that we'll use :after and :before elements to make other things like buttons */
.iphone5 {
position: relative;
height: 520px;
width: 248px;
border-radius: 35px;
margin: 50px auto;
@hengkiardo
hengkiardo / 1_Instructions.md
Created November 23, 2012 09:10 — forked from Daniel15/1_Twitter autoresponder bot.md
Twitter autoresponder bot

Twitter autoresponder bot

By Daniel15 (dan.cx) This is a very simple Twitter autoresponder bot. It requires PECL OAuth extension to be installed (run "pecl install oauth", or if on Windows, grab php-oauth.dll. If using cPanel you can install it via WHM). The authentication is designed for command-line usage, it won't work too well via a web browser. You'll have to sign up for an application on Twitter's site to get the consumer key and secret.

Could be modified to be more advanced (match regular expressions to answer questions, etc.)

@hengkiardo
hengkiardo / gist:4142221
Created November 25, 2012 03:01
QR Code for the Current URL with PHP and Google Charts
function saveImage($your_url, $width, $height, $file) {
$your_url = urlencode($your_url);
$url = 'http://chart.apis.google.com/chart?chs='.$width.'x'.$height.'&cht=qr&chl='.$your_url';
// initialize cURL settings
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
@hengkiardo
hengkiardo / jbookm.js
Last active October 13, 2015 04:57 — forked from irace/gist:1041837
Simple bookmarklet template with jQuery
// Stripped down jQuerify for modern browsers: http://www.learningjquery.com/2009/04/better-stronger-safer-jquerify-bookmarklet
(function() {
var f = function() {
jQuery.noConflict()(function($) {
// Bookmarklet code goes here
});
};
if (typeof jQuery != 'undefined') {
@hengkiardo
hengkiardo / gist:4147311
Created November 26, 2012 09:08
Database configuration file for MySQL service at AppFog Cloud
<?php
$services_json = json_decode(getenv("VCAP_SERVICES"),true);
$mysql_config = $services_json["mysql-5.1"][0]["credentials"];
$username = $mysql_config["username"];
$password = $mysql_config["password"];
$hostname = $mysql_config["hostname"];
$port = $mysql_config["port"];
$db = $mysql_config["name"];
mysql_connect($hostname,$username,$password);
?>