Skip to content

Instantly share code, notes, and snippets.

@mtasuandi
mtasuandi / compress.go
Created January 16, 2017 10:19 — forked from iamralch/compress.go
ZIP archives in Golang
import (
"archive/zip"
"io"
"os"
"path/filepath"
"strings"
)
func zipit(source, target string) error {
zipfile, err := os.Create(target)
@mtasuandi
mtasuandi / MySQLHaversineFormula
Created September 29, 2015 04:14
MySQL Haversine Formula
/**
* MySQL 5.6 >
* Table structure (id {primary, autoincrement}, name {string}, location{spatial, geometry})
*/
SELECT 3956 * 2 * ASIN(SQRT(POWER(SIN((Y(location) - ABS(14.601343)) * PI()/180 / 2), 2)+ COS(ABS(Y(location)) * PI()/180 ) * COS(ABS(14.601343) * PI()/180) * POWER(SIN((X(location) - 120.972882) * PI()/180 / 2), 2) )) AS distance, name
FROM table
WHERE ST_Within(location, Envelope(LineString(POINT(120.972882-10/ABS(COS(RADIANS(14.601343))*69), 14.601343-(10/69)), POINT(120.972882+10/ABS(COS(RADIANS(14.601343))*69), 14.601343+(10/69)))))
ORDER BY distance
/**
@mtasuandi
mtasuandi / GoogleRankCheckerYelp.class.php
Created December 25, 2013 06:07
Google Rank Checker - Yelp.com Perform google search using site:yelp.com biz city category rating:rating(3.0) then return top ten results.
<?php
/**
* @author: M Teguh A Suandi
* @company: Biztech Indonesia (http://biztechindonesia.com)
* @email: teguh.andro@gmail.com
*/
if(@ini_set('max_execution_time', 1200) !== FALSE)
@ini_set('max_execution_time', 1200);
@mtasuandi
mtasuandi / morguefile.class.php
Created December 11, 2013 06:50
Morguefile API Class
<?php
class morguefile {
private $api_id;
private $api_secret;
function __construct($api_id, $api_secret) {
if(!function_exists('curl_init')){
throw new Exception('Curl is required for morguefile API');
}
@mtasuandi
mtasuandi / genericautoresponder
Created June 2, 2013 02:40
Fetching form fields without using RegEx
<?php
$genericform = HTML_FORM;
$document = new DOMDocument();
$document->loadHTML(stripslashes($genericform));
for($i=0; $i<$document->getElementsByTagName('input')->length; $i++)
{
$htmlform = $document->getElementsByTagName('input')->item($i);
if($htmlform->attributes->getNamedItem('type')->value == 'hidden')

The new Secure Password Hashing API in PHP 5.5

The [RFC for a new simple to use password hashing API][rfc] has just been accepted for PHP 5.5. As the RFC itself is rather technical and most of the sample codes are something you should not use, I want to give a very quick overview of the new API:

Why do we need a new API?

Everybody knows that you should be hashing their passwords using bcrypt, but still a surprising number of developers uses insecure md5 or sha1 hashes (just look at the recent password leaks). One of the reasons for this is that the crypt() API is ridiculously hard to use and very prone to programming mistakes.