Skip to content

Instantly share code, notes, and snippets.

View dbabbs's full-sized avatar
Focusing

Dylan Babbs dbabbs

Focusing
View GitHub Profile
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'),
@dbabbs
dbabbs / .bash_profile
Last active September 25, 2018 19:19
# Enable tab completion
source ~/git-completion.bash
# colors!
green="\[\033[0;32m\]"
blue="\[\033[0;34m\]"
purple="\[\033[0;35m\]"
reset="\[\033[0m\]"
# Change command prompt
@dbabbs
dbabbs / CVPixelBuffer -> UIImage.swift
Last active October 4, 2017 00:15
CVPixel Buffer -> UIImage
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
}
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
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');
});
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;
var coordinates = {
lat: geocodeJson.Response.View[0].Result[0].Location.DisplayPosition.Latitude,
long: geocodeJson.Response.View[0].Result[0].Location.DisplayPosition.Longitude
};
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;
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
});
twiml.message(responseMessage + '\nReply with # to learn more information');
res.writeHead(200, {
'Content-Type': 'text/xml'
});
res.end(twiml.toString());