Skip to content

Instantly share code, notes, and snippets.

@marchawkins
marchawkins / analyze-mp3-html5-canvas
Created May 23, 2014 20:44
Using the HTML 5 Canvas element to render out a visualization from an mp3 file. Script loads an mp3 file into an AudioContext object; 2 sound analyzers created to capture left/right audio channel data; as audio file plays, the audio channel is analyzed and written, as a gradient, to the canvas element; only works in browsers supporting the Audio…
<div class="row">
<div class="col-md-3 col-sm-3 col-xs-4">
<canvas id="canvas" width="60" height="130" style="display: block;"></canvas>
<p><button class="btn btn-primary btn-sm" id="play-audio"><span>Play Audio <span class="glyphicon glyphicon-volume-up"></span></span></button></p>
</div><!-- .col -->
<div class="col-md-9 col-sm-9 col-xs-8">
<div class="panel panel-default">
<img src="/content/07-project-diane/04-interfaces/02-audio-visualization/01-audio-mp3-canvas-visualization/one-small-step.jpg" class="img-responsive img-rounded"/>
</div>
</div><!-- .col -->
@marchawkins
marchawkins / google-calendar-event-insert-js
Last active January 14, 2022 18:55
How to connect to the Google Calendar API via the Javascript Client Library and insert an event into a (https://www.google.com/calendar/embed?src=gk0pudanag1bhu35vkv5dunja4%40group.calendar.google.com&ctz=America/New_York). The demo also employs Oauth2 authentication, so the script could read and write to a logged in user's calendar.
<div class="row">
<div class="col-md-2 col-sm-2 col-xs-12">
<button id="authorize-button" style="visibility: hidden" class="btn btn-primary">Authorize</button>
</div><!-- .col -->
<div class="col-md-10 col-sm-10 col-xs-12">
<script type="text/javascript">
// date variables
var now = new Date();
today = now.toISOString();
@marchawkins
marchawkins / google-calendar-read-js
Created May 21, 2014 04:32
How to connect to the Google Calendar API via the Javascript Client Library to retrieve calendar events. The demo also employs Oauth2 authentication, so the script could read a logged in user's calendar. This demo **only** reads a public calendar. You need the calendar's id (from google) in your own code to retrieve any events. For more info, vi…
<div class="row">
<div class="col-md-2 col-sm-2 col-xs-12">
<button id="authorize-button" style="visibility: hidden" class="btn btn-primary">Authorize</button>
</div><!-- .col -->
<div class="col-md-10 col-sm-10 col-xs-12">
<script type="text/javascript">
// date functions
Date.prototype.getWeek = function(start) {
start = start || 0;
@marchawkins
marchawkins / get-weather-by-address.html
Last active July 29, 2021 02:28
Using the OpenWeatherMap and Google's geolocation APIs to get the current weather for the user-specified location. The user inputs a location, which is geocoded using Google Maps API. Uses the OpenWeatherMap API ((http://openweathermap.org/)) to get the data. Data is returned in JSON format. Most major browsers supported, including IE9, Chrome, …
<div class="row">
<div class="col-md-2 col-sm-2 col-xs-2">
<p><button class="btn btn-primary btn-sm" id="get-weather-btn"><span>Get Weather</span></button></p>
</div><!-- .col -->
<div class="col-md-10 col-sm-10 col-xs-10">
<div class="panel panel-default">
<div class="panel-heading">Weather &amp; Location Response</div>
<div class="panel-body">
<p>Enter Address: <input id="address" type="text" class="form-control"/></p>
<p>Lat/Long: <input id="location-lat-long" type="text" class="form-control"/></p>
@marchawkins
marchawkins / natural-language-dates.html
Created March 18, 2014 04:58
Using the datejs library (http://www.datejs.com/) to process natural language speech and return a specific date, and speak the result with the html 5 speech synthesis api. There seems to be a few bugs when combining relative dates ("today", "tomorrow") with times; all times seem to render as AM. Slight bug with the speech as it sometimes says "X…
<div class="row">
<div class="col-md-4 col-sm-4 col-xs-12">
<p>Click a date below:</p>
<ul>
<li><a href="#" title="Today" class="date-link">Today</a></li>
<li><a href="#" title="Tomorrow" class="date-link">Tomorrow</a></li>
<li><a href="#" title="Tomorrow at 7am" class="date-link">Tomorrow at 7:00 AM</a></li>
<li><a href="#" title="Yesterday at 5pm" class="date-link">Yesterday at 5:00 PM</a><br/><small><em>This is broken, always displayed as 5am</em></small></li>
<li><a href="#" title="Next Monday" class="date-link">Next Monday</a></li>
<li><a href="#" title="March 30th" class="date-link">March 30th</a></li>
@marchawkins
marchawkins / get-weather-by-geolocation.html
Created March 15, 2014 05:03
Using the OpenWeatherMap and HTML 5 geolocation APIs to get the current weather for the user's current location. The location is determined by the user's system. Due to privacy concerns, the user must give permission for the browser to access the location. If the user disallows location access, the lat/long retrieved is based on the user's ip ad…
<div class="row">
<div class="col-md-2 col-sm-2 col-xs-2">
<p><button class="btn btn-primary btn-sm" id="get-weather-btn"><span>Get Weather</span></button></p>
</div><!-- .col -->
<div class="col-md-10 col-sm-10 col-xs-10">
<div class="panel panel-default">
<div class="panel-heading">Weather &amp; Location Response</div>
<div class="panel-body">
<p>Lat/Long: <input id="location-lat-long" type="text" class="form-control"/></p>
<p>Weather: <textarea id="weather" class="form-control"></textarea></p>
@marchawkins
marchawkins / get-weather.html
Created March 9, 2014 08:17
Use the OpenWeatherMap api to retrieve current weather conditions by providing an address or latitude and longitude. Uses the OpenWeatherMap API (http://openweathermap.org/) to get the data. Data is returned in JSON format. For this test, input an address and hit the "Get Weather" button. The current weather conditions will be shown in the texta…
<div class="row">
<div class="col-md-2 col-sm-2 col-xs-2">
<p><button class="btn btn-primary btn-sm" id="get-weather-btn"><span>Get Weather</span></button></p>
</div><!-- .col -->
<div class="col-md-10 col-sm-10 col-xs-10">
<div class="panel panel-default">
<div class="panel-heading">OpenWeatherMap API Response</div>
<div class="panel-body">
<p>Enter Address: <input type="text" id="address" class="form-control" placeholder="City, State"/></p>
<textarea id="weather" class="form-control"></textarea>
@marchawkins
marchawkins / geocode-user-input-address.html
Created March 7, 2014 06:43
Using the google maps geocoding api to find an address input by the user. The address is then plotted on a google map. The location is determined by the value of the textfield. Initially, the map will display a generic location (nyc). Most major browsers supported, including IE9, Chrome, Safari, Opera and Firefox. For this test, enter an address…
<div class="row">
<div class="col-md-2 col-sm-2 col-xs-2">
<p><button class="btn btn-primary btn-sm" id="map-address-btn"><span>Find It</span></button></p>
</div><!-- .col -->
<div class="col-md-10 col-sm-10 col-xs-10">
<div class="panel panel-default">
<div class="panel-heading">Location Response</div>
<div class="panel-body">
<p>Enter Address: <input id="location-address" type="text" class="form-control" placeholder="Street, City, State"/</p>
<p>Map:</p><div id="map-canvas" style="height: 400px;"></div>
@marchawkins
marchawkins / geocode-current-geolocation.html
Created March 7, 2014 06:14
Using the HTML 5 geolocation api get the user's current location and plot it on a google map. The location is determined by the user's system. Due to privacy concerns, the user must give permission for the browser to access the location. If the user disallows location access, the lat/long retrieved is based on the user's ip address. Most major b…
<div class="row">
<div class="col-md-2 col-sm-2 col-xs-2">
<p><button class="btn btn-primary btn-sm" id="get-location-btn"><span>Get Location</span></button></p>
</div><!-- .col -->
<div class="col-md-10 col-sm-10 col-xs-10">
<div class="panel panel-default">
<div class="panel-heading">Location Response</div>
<div class="panel-body">
<p>Lat/Long: <input id="location-lat-long" type="text" class="form-control"/></p>
<p>Address: <input id="location-address" type="text" class="form-control"/</p>
@marchawkins
marchawkins / geocode-address.html
Created March 6, 2014 06:01
How to use the HTML 5 geolocation api to geocode and address and plot it on a google map. For this test, input an address and hit the "Map It" button. The location will be shown on the map.
<div class="row">
<div class="col-md-2 col-sm-2 col-xs-2">
<p><button class="btn btn-primary btn-sm" id="get-map-btn"><span>Map It</span></button></p>
</div><!-- .col -->
<div class="col-md-10 col-sm-10 col-xs-10">
<div class="panel panel-default">
<div class="panel-heading">Location Response</div>
<div class="panel-body">
<p>Enter Address: <input id="address" type="text" class="form-control"/></p>
<div id="map-canvas" style="min-height: 400px;"></div>