Skip to content

Instantly share code, notes, and snippets.

View sydlawrence's full-sized avatar

Syd Lawrence sydlawrence

View GitHub Profile
@sydlawrence
sydlawrence / geolocation.js
Created September 26, 2013 00:39
HTML5 geolocation
navigator.geolocation.getCurrentPosition(function(result) {
var location = data.coords;
});
@sydlawrence
sydlawrence / distance.js
Created September 26, 2013 00:38
Get a distance from a location using HTML geolocation
var calculateDistance = function(location1, location2) {
// this is where we want to calculate the distance from. You can of course split this out so that the function
var origin = {longitude:50,latitude:1};
// first calculate the locations into radians.
var radlat1 = Math.PI * location1.latitude/180;
var radlat2 = Math.PI * location2.latitude/180;
var radlon1 = Math.PI * location1.longitude/180;
var radlon2 = Math.PI * location2.longitude/180;
var theta = location2.longitude-location1.latitude;
@sydlawrence
sydlawrence / sundata.js
Last active December 23, 2015 23:09
sunrise and sunset data for a country
var country = "UK";
// fetch results from yql
var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20location%20in%20(select%20id%20from%20weather.search%20where%20query%20%3D%20%22"+country+"%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=?";
$.getJSON(url, function(data) {
var sunData = {}
// if there are results
if (data.query.results.channel.length > 0) {
var result = data.query.results.channel[0];
@sydlawrence
sydlawrence / ipgeolocate.html
Created September 26, 2013 00:14
Geolocating from ip address
<script src="http://j.maxmind.com/app/country.js"></script>
<script>
var country = geoip_country_name();
</script>
@sydlawrence
sydlawrence / userlocation.js
Created September 25, 2013 22:03
Get User Location
navigator.geolocation.getCurrentPosition(function(result) {
var location = data.coords;
// This now consists of:
// latitude
// longitude
// altitude (if avaiable)
// various other attributes
@sydlawrence
sydlawrence / forward.sms.php
Created August 28, 2013 13:46
Forward SMS via Twilio
<?php
$to = "+447515354472";
?>
<Response>
<Sms to="<?php echo $to;?>" from="<?php echo $_POST['From'];?>"><?php echo $_POST['Body']; ?></Sms>
</Response>
@sydlawrence
sydlawrence / gist:6130295
Created August 1, 2013 10:44
Tweet buttons
var reply = "https://twitter.com/intent/tweet?in_reply_to="+tweet.id;
var retweet = "https://twitter.com/intent/retweet?tweet_id="+tweet.id;
var star = "https://twitter.com/intent/favourite?tweet_id="+tweet.id;
@sydlawrence
sydlawrence / twitterregs.js
Last active December 18, 2015 09:19
Simple JS to add the twitter "new guidlines" bs
function addTwitterBSRegs(id) {
var html = "<a class='reply' target='_blank' href='https://twitter.com/intent/tweet?in_reply_to="+id+"'>reply</a>";
html += "<a class='retweet' target='_blank' href='https://twitter.com/intent/retweet?tweet_id="+id+"'>retweet</a>";
html += "<a class='star' target='_blank' href='https://twitter.com/intent/favourite?tweet_id="+id+"'>star</a>";
html += "<a class='twitter' target='_blank' href='https://twitter.com/'>twitter</a>";
return html;
}
@sydlawrence
sydlawrence / WMAS woz ere
Last active December 17, 2015 23:59
WMAS HTML tag
<!--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
/\/\ WMAS woz 'ere \/\/ Client Name Here \/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
-->
@sydlawrence
sydlawrence / gist:5407013
Last active December 16, 2015 08:39
Sending an SMS via PHP.
<?php
// include the twilio php help library
require "Services/Twilio.php";
// Setup your credentials
$account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$auth_token = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY";
// Step 3: instantiate a new Twilio Rest Client