Skip to content

Instantly share code, notes, and snippets.

View sydlawrence's full-sized avatar

Syd Lawrence sydlawrence

View GitHub Profile
@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 / 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 / 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 / geolocation.js
Created September 26, 2013 00:39
HTML5 geolocation
navigator.geolocation.getCurrentPosition(function(result) {
var location = data.coords;
});
@sydlawrence
sydlawrence / twilioSoundcloud.php
Last active December 23, 2015 23:09
upload twilio recording to soundcloud
<?php
// download the recording to the local machine
file_put_contents("recording.wav", file_get_contents($_POST['RecordingUrl']));
// setup the track info to send to soundcloud
$track = array(
'track[asset_data]' => '@recording.wav' // adding @ adds the contents to $_FILES
);
// upload the sound using the soundcloud php sdk
/*
* (c) 2011 Dominik Schmidt <domme@tomahawk-player.org>
*/
var DummyResolver = Tomahawk.extend(TomahawkResolver,
{
settings:
{
name: 'Dummy Resolver',
weight: 75,
@sydlawrence
sydlawrence / under-pressure-cheats.js
Last active December 24, 2015 14:19
Javascript under pressure cheats...
// Paste these in chunks into the developer console. BEFORE you press "Start game"
startGame();
editor.setValue("function doubleInteger(i) { return i*2; }");
runCode();
// wait for the previous tests to run and succeed, then paste the next
runCode();
editor.setValue("function isNumberEven(i) { return !(i%2); }");
@sydlawrence
sydlawrence / app.js
Last active August 29, 2015 13:56
The basic launchpad node app
var midiConnector = require('midi-launchpad').connect(midiport);
// wait for the connector to be ready
midiConnector.on("ready",function(launchpad) {
launchpad.on("press", function(button){
button.light(launchpad.colors.green.high);
});
launchpad.on("release", function(button) {
button.light(launchpad.colors.off);
});
@sydlawrence
sydlawrence / .gitignore
Created June 18, 2014 16:19
.gitignore
# Mac OSX Specific
# ----------------
.DS_Store
._*
.Spotlight-V100
.Trashes
# Windows Specific
# ----------------
Thumbs.db
{
"requireCapitalizedConstructors": true,
"requireMultipleVarDecl": true,
"disallowEmptyBlocks": true,
"disallowSpaceAfterObjectKeys": true,
"requireCommaBeforeLineBreak": true,
"requireParenthesesAroundIIFE": true,
"disallowKeywords": [
"with"
],