Skip to content

Instantly share code, notes, and snippets.

@niklasvincent
niklasvincent / geo.php
Created June 8, 2012 08:09
MongoDB really shines in this comparison
// MySQL
$sql = "SELECT all, the fields, you, want, ((ACOS(SIN(c.Latitude * PI() / 180) * SIN(" . $lat . " * PI() / 180) + COS(c.Latitude * PI() / 180) * COS(" . $lat . " * PI() / 180) * COS((c.Longitude - " . $lng . ") * PI() / 180)) * 180 / PI()) * 60 * 2) as distance FROM places ORDER BY distance DESC;";
// MongoDB
$this->places->find(array( 'loc' => array( '$near' => array($lat, $lng) ) ));
@niklasvincent
niklasvincent / gist:2639727
Created May 8, 2012 22:00
Sammy.js + Mustache + seamless presentation of REST API data
var model = {
'/animals': {
'verb': "get",
'template': '<div id="animal-{{ID}}"> \
<a href="#/animals/{{ID}}"><h2>{{title}}</h2></a> \
<h3>{{time_added}}</h3> \
<img src="{{thumbnail.0}}" /></div>'
},
@niklasvincent
niklasvincent / FacebookEvent.php
Created August 26, 2011 10:20
Facebook Event WP Plugin
<?php
/*
Plugin Name: Facebook Event
Plugin URI: http://www.studentlund.se
Description: Detect Facebook event URL in post and update post content to match the event
Author: Niklas Lindblad
Version: 0.1
Author URI: http://niklas.lindblad.info
*/
@niklasvincent
niklasvincent / facebook-event.php
Created August 18, 2011 11:50
Get details about Facebook event
<?php
function is_facebook_event( $url )
{
return ( preg_match("/http:\/\/www\.facebook\.com\/event.php\?eid=[0-9]*\.*/", $url) == 1 );
}
function get_facebook_event ( $url )
{
$m = explode('=', $url);