Skip to content

Instantly share code, notes, and snippets.

View mortenjust's full-sized avatar

Morten Just mortenjust

View GitHub Profile
@mortenjust
mortenjust / gist:2072528
Created March 18, 2012 13:35
php 301 redirect
if (substr($_SERVER['HTTP_HOST'],0,3) != 'www') {
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.'.$_SERVER['HTTP_HOST']
.$_SERVER['REQUEST_URI']);
@mortenjust
mortenjust / gist:2158504
Created March 22, 2012 14:00
getDistance calculate distance in km in javascript
function getDistance(lon1, lat1, lon2, lat2) {
var R = 6371; // Radius of the earth in km
var dLat = toRad(lat2-lat1);
var dLon = toRad(lon2-lon1);
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
return R * c; // Distance in km
}
@mortenjust
mortenjust / gist:2158563
Created March 22, 2012 14:12
suggest from google maps api in javascript
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<title>JS Bin</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
@mortenjust
mortenjust / gist:2183587
Created March 24, 2012 14:35
localstorage javascript
$(document).ready(function() {
var edit = document.getElementById('editableList');
$(edit).blur(function() {
localStorage.setItem('toDoData', this.innerHTML);
});
//when the page loads
if(localStorage.getItem('toDoData')){
edit.innerHTML = localStorage.getItem('toDoData');
}
});
@mortenjust
mortenjust / gist:2193225
Created March 25, 2012 12:12
save radio buttons with localstorage jquery javascript
// this in doc ready
$(function()
{
$('input[type=radio]').each(function()
{
var state = JSON.parse( localStorage.getItem('radio_' + $(this).attr('id')) );
if (state) this.checked = state.checked;
});
@mortenjust
mortenjust / app.yaml
Created March 28, 2012 10:49 — forked from darktable/app.yaml
GAE: App.yaml designed for serving a static site on Google App Engine (Python). Copy your static html and files into a folder called "static" next to app.yaml. Contains a bunch of mimetype declarations from html5boilerplate's .htaccess. May not be neces
application: you-app-name-here
version: 1
runtime: python
api_version: 1
default_expiration: "30d"
handlers:
- url: /(.*\.(appcache|manifest))
mime_type: text/cache-manifest
@mortenjust
mortenjust / gist:2277443
Created April 1, 2012 18:07
sort array javascript
// Sort by price high to low
//homes.sort(sort_by('price', true, parseInt));
var sort_by = function(field, reverse, primer){
var key = function (x) {return primer ? primer(x[field]) : x[field]};
return function (a,b) {
var A = key(a), B = key(b);
return ((A < B) ? -1 :
(A > B) ? +1 : 0) * [-1,1][+!!reverse];
}
function getParameterByName(url, name) {
var match = RegExp('[?&]' + name + '=([^&]*)').exec(url);
return match?decodeURIComponent(match[1].replace(/\+/g, ' ')):null;
}
@mortenjust
mortenjust / index.html
Created April 22, 2012 13:28
iphone meta
<meta name="viewport" content="initial-scale=1.0, width=device-width, height=device-height, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<link rel="apple-touch-icon-precomposed" href="maps-icon.png"/>
<link rel="apple-touch-startup-image" href="splash.png" />
@mortenjust
mortenjust / gist:2499441
Created April 26, 2012 13:09
spotify api metaapi tracks artists coffeescript
window.spotifyLink = (tracks) ->
extractID = (track) ->
track.replace(/spotify.track./,"")
"spotify:trackset:Title:#{extractID(track) for track in tracks}"
window.playlistLink = (tracks) ->
"<b><a href='#{spotifyLink(tracks)}'>Spotify playlist</a></b>
<small>Found #{tracks.length}/#{HUNTED.chart.entities.length}</small>
"