Skip to content

Instantly share code, notes, and snippets.

<!-- make a synchronous cross-domain request to The Echo Nest API -->
<!DOCTYPE html>
<html>
<head>
<title>Echo Nest API Cross-Domain Example</title>
</head>
<body>
<h1>Echo Nest API Cross-Domain Example</h1>
<p><strong>Results:</strong></p>
function Nest(api_key) {
this.api_key = api_key;
}
Nest.prototype = {
analyzeFile: function(file, type, options) {
var form = new FormData();
form.append('api_key', this.api_key);
form.append('track', file);
form.append('filetype', type);
<!DOCTYPE html>
<html>
<head>
<title>Analyze</title>
<script src="nest.js" type="text/javascript"></script>
</head>
<body>
<h1>Analyze</h1>
@also
also / modernizr-audio-api.js
Created March 19, 2011 23:26
Modernizr tests for the Web Audio API and Audio Data API
// Test for the Web Audio API <http://chromium.googlecode.com/svn/trunk/samples/audio/specification/specification.html>
Modernizr.addTest('webAudioApi', function () {
return !!(window.webkitAudioContext || window.AudioContext);
});
// Test for the Audio Data API <https://wiki.mozilla.org/Audio_Data_API>
Modernizr.addTest('audioDataApi', function () {
return !!new Audio().mozSetup;
});
@also
also / typedarray-subarray.js
Created April 10, 2011 01:37
Fix TypedArray.subarray in WebKit and Mozilla
(function () {
var typedArrays = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array];
if (window.Float64Array) {
typedArrays.push(Float64Array);
}
// fix for webkit pre slice rename
// https://bugs.webkit.org/show_bug.cgi?id=53618
if (!Float32Array.prototype.subarray) {
typedArrays.forEach(function (cls) {
@also
also / mozilla-readasarraybuffer.js
Created April 10, 2011 05:47
readAsArrayBuffer polyfill for Firefox 4
if (!FileReader.prototype.readAsArrayBuffer) {
FileReader.prototype.readAsArrayBuffer = function readAsArrayBuffer () {
this.readAsBinaryString.apply(this, arguments);
this.__defineGetter__('resultString', this.__lookupGetter__('result'));
this.__defineGetter__('result', function () {
var string = this.resultString;
var result = new Uint8Array(string.length);
for (var i = 0; i < string.length; i++) {
result[i] = string.charCodeAt(i);
}
@also
also / utf-16.js
Created April 10, 2011 22:17
Decode JavaScript UTF-16 arrays
// http://www.ietf.org/rfc/rfc2781.txt
function decodeUtf16(w) {
var i = 0;
var len = w.length;
var w1, w2;
var charCodes = [];
while (i < len) {
var w1 = w[i++];
if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
charCodes.push(w1);
var host = "localhost:9999"
var page = 1
var ws = new WebSocket("ws://" + host + "/devtools/page/" + page)
ws.onmessage = function(m) {console.log(m.data)}
var counter = 0
var send = function (method, params) {
ws.send(JSON.stringify({id: counter++, 'method': method, 'params': params}))
}
@also
also / gist:8758130
Created February 1, 2014 20:17
lead mathematica import
Import["http://lead.ryanberdeen.com/render?target=randomWalkFunction(%\
27hello%2C+world%27)", "JSON"]
var eslint = require('eslint');
var CLIEngine = eslint.CLIEngine;
var linter = eslint.linter;
var baseConfig = {format: 'stylish'};
console.log(baseConfig.format);
new CLIEngine({baseConfig: baseConfig}).getConfigForFile('.');
console.log(baseConfig.format);