Skip to content

Instantly share code, notes, and snippets.

View SimonJThompson's full-sized avatar
👨‍💻

Simon Thompson SimonJThompson

👨‍💻
View GitHub Profile
@SimonJThompson
SimonJThompson / flightpath.css
Last active November 30, 2021 19:18
Google Maps Animated Flight Paths
@charset "utf-8";
/*! normalize.css v1.1.0 | MIT License | git.io/normalize */
article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block}audio,canvas,video{display:inline-block;*display:inline;*zoom:1}audio:not([controls]){display:none;height:0}[hidden]{display:none}html{font-size:100%;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}html,button,input,select,textarea{font-family:sans-serif}body{margin:0}a:focus{outline:thin dotted}a:active,a:hover{outline:0}h1{font-size:2em;margin:.67em 0}h2{font-size:1.5em;margin:.83em 0}h3{font-size:1.17em;margin:1em 0}h4{font-size:1em;margin:1.33em 0}h5{font-size:.83em;margin:1.67em 0}h6{font-size:.67em;margin:2.33em 0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}blockquote{margin:1em 40px}dfn{font-style:italic}hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0}mark{background:#ff0;color:#000}p,pre{margin:1em 0}code,kbd,pre,samp{font-family:monospace,serif;_font-family:'courier new',monospace;f
@SimonJThompson
SimonJThompson / data.json
Last active August 29, 2015 14:13
D3 - Updating Data
{
"nodes" : [
{"name":"test","1990":20, "1991":22, "1992":19},
{"name":"test2","1990":10, "1991":12, "1992":16},
{"name":"test3","1990":6, "1991":22, "1992":30}
]
}
@SimonJThompson
SimonJThompson / haversine-miles.js
Last active November 7, 2020 01:16
Use haversine to calculate the distance in miles between two lat-long points.
/* Modified from http://stackoverflow.com/questions/14560999/using-the-haversine-formula-in-javascript */
function toRad(v){return v * Math.PI / 180;}
function kmToMiles(km) {return (km * 0.62137).toFixed(2);}
var l1 = LatLong(0,0);
var l2 = LatLong(0,0);
function LatLong(lat, lon) {
return {Latitude: lat, Longitude: lon}
@SimonJThompson
SimonJThompson / array_to_attr.php
Created May 16, 2014 09:37
Function to convert an associative array to a string of HTML element attributes.
<?php
/*
Takes an associative array and converts them to HTML element attributes
*/
function array_to_attr($attrs) {
$r="";
if(is_array($attrs)) {
foreach($attrs as $attr => $val) {
@SimonJThompson
SimonJThompson / get_contrasting_colour.php
Created May 15, 2014 11:38
PHP function, returns either black or white hex value to contrast with a given hex colour.
/*
Original code from http://www.webmasterworld.com/forum88/9769.htm, tweaked to accomodate for shorthand hex (#fff)
*/
function get_contrasting_colour($hex) {
$hex = str_replace('#', '', $hex);
$l=2;
if(strlen($hex==3)){$l=1;}
$c_r = hexdec(substr($hex, 0, $l));
$c_g = hexdec(substr($hex, 2, $l));
/* This code will validate all elements in a form (elements that are included in form.elements, that is).
By "Validate", it is meant that the field is not empty. No additional checks are made such as for valid email addresses,
phone numbers or anything similar. Any empty / failed fields will be given a red border color and text before an alert appears informing the user that they need to complete the stated fields */
function validateForm(form)
{
var error_count = 0; // Holds the amount of errors
var error_list = new Array(); // The array (list) of errors found.
@SimonJThompson
SimonJThompson / college-simpleslide.js
Last active December 15, 2015 03:38
Crude and simple background-image slideshow class in JavaScript. No effects.
/*
This class allows the creation of a simple slideshow.
It requires an array of image locations and a target element ID.
It does not fade images, simply substitutes the background-image property.
*/
var slideshow = function()
{
var self = this;