Skip to content

Instantly share code, notes, and snippets.

@r8n5n
r8n5n / index.html
Last active October 23, 2019 10:06
Twinkling star field using canvas/js
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>Starfield</title>
</head>
@r8n5n
r8n5n / responsive_iframe.html
Created January 22, 2016 16:24
Responsive iframe
<!-- set the max width accordingly -->
<div style="margin: 0 auto; max-width: 960px; position: relative;">
<!-- set the padding % as the aspect ratio of the content e.g. 960/560 = 5.833333 -->
<div style="padding-bottom: 58.33333333%;">
<!-- the width=1; max-width=100% is for iOS -->
<iframe scrolling="no" src="urls/to/iframe.html" style="position: absolute;width: 1px;min-width:100%;height: 100%;"></iframe>
</div>
</div>
@r8n5n
r8n5n / randomPointInTriangle.js
Created January 22, 2016 16:19
Pick a random point within a triangle
/**
* Pick a random point within a triangle
* @param {Object} a Point {x:# , y:#}
* @param {Object} b Point {x:# , y:#}
* @param {Object} c Point {x:# , y:#}
* @returns Object {x:# , y:#}
*
* @see http://parametricplayground.blogspot.co.uk/2011/02/random-points-distributed-inside.html
*/
@r8n5n
r8n5n / MySQL distance
Created August 13, 2014 12:04
MySQL Function to get distance between 2 locations (lat,lon) in KM
DELIMITER $$
DROP FUNCTION IF EXISTS d $$
CREATE FUNCTION d(lat1 FLOAT, lon1 FLOAT, lat2 FLOAT, lon2 FLOAT) RETURNS FLOAT
DETERMINISTIC
BEGIN
DECLARE R FLOAT;
DECLARE rad FLOAT;
DECLARE a FLOAT;
DECLARE d FLOAT;