Skip to content

Instantly share code, notes, and snippets.

View ismaelc's full-sized avatar

Chris Ismael ismaelc

View GitHub Profile
@ismaelc
ismaelc / playAudioTwilioTextToVoice.js
Created June 8, 2013 00:50
node.js function snippet showing a TwiML response to get Twilio to play audio over the call. It also shows a Mashape API that does text-to-voice. We get a link to an MP3 of the processed text. How convenient. Full source code is at https://github.com/ismaelc/twilio-translator
// Returns the Twiml that instructs Twilio to play an audio file from a text to voice API
exports.getTwimlToCall = function (req, res) {
var translatedText = req.query.t;
var lang = req.query.lang;
// Call the text to voice API that can handle local voices
request({
url: 'https://yambal-text-to-voice.p.mashape.com/url?lang=' + lang + '&text=' + translatedText,
method: 'GET',
headers: {
@ismaelc
ismaelc / unirestnode.js
Created October 22, 2013 22:13
Creating an HTTP request using Unirest for node.js
unirest.post('http://httpbin.org/post')
.headers({ 'Accept': 'application/json' })
.send({ "parameter": 23, "foo": "bar" })
.end(function (response) {
console.log(response.body);
});
@ismaelc
ismaelc / getvoice.js
Last active December 26, 2015 13:59
getvoice.js from the SendGrid voice relay demo
var unirest = require('unirest'),
Firebase= require('firebase'),
config = require('./config');
var myRootRef = new Firebase(config.firebase.hostname);
// Method below is POSTed to by Sendgrid's Inbound Parse API (Webhooks) - http://bit.ly/11h7K2P
// 1. Accepts 'subject' and 'text'
// 2. Calls a Mashape text-to-speech API on 'subject'
// 3. Pushes resulting mp3 to Firebase to initiate hook to play mp3 from index.html
@ismaelc
ismaelc / firebaseCallback.js
Created October 25, 2013 21:56
Snippet highlighting the Firebase bits from the Sendgrid voice relay demo
var myDataRef = new Firebase('https://<your Firebase name>.firebaseio.com/');
myDataRef.on('child_added', function(snapshot) {
audio.src = "data:audio/mp3;base64," + $.base64.encode(snapshot.val().voice);
audio.play();
$("#subject").text(snapshot.val().subj);
$("#text").text(snapshot.val().text);
});
@ismaelc
ismaelc / index.html
Last active December 27, 2015 00:59
Application initializes the Parse Javascript SDK and calls our Cloud Code "yodaSpeakFunction"
<!doctype html>
<head>
<title>My Parse App</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.2.12.min.js"></script>
</head>
<body>
<script type="text/javascript">
@ismaelc
ismaelc / main.js
Last active December 27, 2015 00:59
Define the Cloud Code "yodaSpeakFunction" and initialize/call the Cloud Module "yodaSpeak"
// Cloud Code 'yodaSpeakFunction'
// Import Cloud Module from /cloud folder
// Initialize Cloud Code with your Mashape key (http://mashape.com/keys)
var yodaClient = require('cloud/yoda-1.0.0.js');
yodaClient.initialize('<Enter your Mashape key here>');
Parse.Cloud.define("yodaSpeakFunction", function(request, response) {
// Call 'yodaSpeak' Cloud Module passing in 'sentence' parameter
@ismaelc
ismaelc / yoda-1.0.0.js
Last active December 27, 2015 01:08
The Cloud Module Yoda Speak where the Mashape API is called
// Cloud Module yoda-1.0.0.js
// Set url of Mashape API to call
var url = 'https://yoda.p.mashape.com/yoda';
var key = '';
module.exports = {
// Method to initialize module
initialize: function(mashapeKey) {
@ismaelc
ismaelc / unirest_pcl.cs
Created November 21, 2013 23:11
Unirest PCL demo
var result = await Unirest.get("https://mashape.p.mashape.com/apis")
.header("X-Mashape-Authorization", "MyApiKey")
.asJsonAsync<ApisResult>();
@ismaelc
ismaelc / bbyopen.js
Last active December 29, 2015 09:39
var Request = unirest.get("https://bbyopen-bbyopen.p.mashape.com/products?apiKey=<insert Best Buy API key here>")
.headers({
"X-Mashape-Authorization": "<insert Mashape key here>"
})
.end(function (response) {
console.log(response);
});
<?xml version="1.0" encoding="UTF-8"?>
<quotes>
<quote>
<symbol>AAPL</symbol>
<trade_date>2013-10-17T15:45:06-04:00</trade_date>
<bid_date>2013-10-17T15:45:05-04:00</bid_date>
<ask_date>2013-10-17T15:45:05-04:00</ask_date>
<open>499.98</open>
<high>504.78</high>
<low>499.68</low>