Skip to content

Instantly share code, notes, and snippets.

View deadlysyn's full-sized avatar
☁️
yelling at clouds

Mike Hoskins deadlysyn

☁️
yelling at clouds
View GitHub Profile
middleware.parseRequest = function(req, res, next) {
if (req.body.latitude && req.body.longitude) {
// build up yelp api query string...
let q = `?term=${SEARCHTERM}&latitude=${req.body.latitude}&longitude=${req.body.longitude}&limit=${APILIMIT}&open_now=true&sort_by=rating`
// how much you're willing to spend
switch (req.body.price) {
case '$':
q += '&price=1'
break
var m = require('./middleware') // import ./middleware/index.js
// ...
app.post('/random', m.logRequest, m.parseRequest, function(req, res, next) {
req.session.save(function(err) {
res.redirect('/random')
})
})
app.use(session({
store: new memstore({
checkPeriod: 3600000 // 1 hour in ms
}),
resave: false,
saveUninitialized: false,
secret: secret
}))
var ip = process.env.IP || '0.0.0.0'
var port = parseInt(process.env.PORT, 10) || 3000
var secret = process.env.SECRET || 'some random string'
// environment config
var ip = process.env.IP || '0.0.0.0',
port = parseInt(process.env.PORT, 10) || 3000,
secret = process.env.SECRET || 'some random long string we should read from the environment'
/*
* template helpers
*/
// truncate long strings; only add ellipsis on truncation
app.locals.shorten = function(str, len = 30) {
if (str.length > len) {
str = str.substring(0,len).trim() + '...'
}
return str
function updateMapURL(address) {
let maps = 'https://maps.google.com?q='
if (bowser.iphone) {
maps = 'maps:q='
} else if (bowser.android) {
maps = 'geo:0,0?q='
}
route.addEventListener("click", function() {
location.href = maps + encodeURIComponent(address)
})
var geoOpts = {
enableHighAccuracy: true,
maximumAge: 300000,
timeout: 20000
}
if (!navigator.geolocation || !navigator.cookieEnabled) {
location.href = '/nolocation'
} else {
navigator.geolocation.getCurrentPosition(geoSuccess, geoError, geoOpts)
}
function geoSuccess(position) {
latitude.value = position.coords.latitude
longitude.value = position.coords.longitude
loading.innerHTML = 'FIND <i class="fas fa-utensils fa-lg" aria-hidden="true"></i> FOOD'
}
<% include partials/header %>
<body id="list">
<script defer src="/js/list.js"></script>
<div id="list-content">
<% results.forEach(function(biz) { %>
<% if (biz.image_url) { %>
<div class="list-item" style="background-image: url('<%= biz.image_url %>'); background-position: center; background-size: cover">
<% } else { %>
<div class="list-item" style="background-color: rgba(0, 0, 0, 0.5);">
<% } %>