This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(plotly) | |
df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_us_cities.csv') | |
df$q <- with(df, cut(pop, quantile(pop))) | |
levels(df$q) <- paste(c("1st", "2nd", "3rd", "4th", "5th"), "Quantile") | |
df$q <- as.ordered(df$q) | |
g <- list( | |
scope = 'usa', | |
projection = list(type = 'albers usa'), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func pixelToImage(pixelBuffer: CVPixelBuffer) -> UIImage? { | |
let context = CIContext() | |
let ciImage = CIImage(cvPixelBuffer: pixelBuffer) | |
if let image = context.createCGImage(ciImage, from: ciImage.extent) { | |
return UIImage(cgImage: image) | |
} | |
return nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const express = require('express'); | |
const MessagingResponse = require('twilio').twiml.MessagingResponse; | |
const bodyParser = require('body-parser'); | |
const request = require('request'); | |
const app = express(); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ | |
extended: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.post('/sms', (req, res) => { | |
const twiml = new MessagingResponse(); | |
twiml.message('Hello, there!'); | |
res.writeHead(200, {'Content-Type': 'text/xml'}); | |
res.end(twiml.toString()); | |
}); | |
http.createServer(app).listen(1337, () => { | |
console.log('Express server listening on port 1337'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.post('/sms', (req, res) => { | |
const twiml = new MessagingResponse(); | |
var incoming = req.body.Body; | |
var searchQuery = incoming.split(' near ')[0]; //Extract the search query | |
var locationString = incoming.split(' near ')[1]; //Extract the location | |
var geocodeURL = 'https://geocoder.cit.api.here.com/6.2/geocode.json' + | |
'?app_id=' + hereID + | |
'&app_code=' + hereCode + | |
'&searchtext=' + locationString; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var coordinates = { | |
lat: geocodeJson.Response.View[0].Result[0].Location.DisplayPosition.Latitude, | |
long: geocodeJson.Response.View[0].Result[0].Location.DisplayPosition.Longitude | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var placesURL = 'https://places.cit.api.here.com/places/v1/autosuggest' + | |
'?at=' + coordinates.lat + ',' + coordinates.long + | |
'&q=' + searchQuery.replace(/ /g, '+') + | |
'&app_id=' + hereID + | |
'&tf=plain' + | |
'&app_code=' + hereCode; | |
request.get(placesURL, (error, response, body) => { | |
let placesJson = JSON.parse(body); | |
var placeResults = placesJson.results; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var responseMessage = 'Here are the ' + resultAmount + ' closest ' + searchQuery + | |
' places to you: \n'; | |
for (i = 0; i < resultAmount; i++) { | |
if (placeResults[i].resultType != 'category') { | |
places.push({ | |
name: placeResults[i].title, | |
category: placeResults[i].category, | |
address: placeResults[i].vicinity | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
twiml.message(responseMessage + '\nReply with # to learn more information'); | |
res.writeHead(200, { | |
'Content-Type': 'text/xml' | |
}); | |
res.end(twiml.toString()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
twiml.message(places[parseInt(incoming) - 1].name + ' is located at ' + places[parseInt(incoming) - 1].address); | |
res.writeHead(200, { | |
'Content-Type': 'text/xml' | |
}); | |
res.end(twiml.toString()); | |
places = []; //Empty places to restart |
OlderNewer