Created
July 15, 2015 17:32
-
-
Save mayfer/d61d57098f2578e51e23 to your computer and use it in GitHub Desktop.
Caching
This file contains hidden or 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
<!doctype html> | |
<html> | |
<head> | |
<title>weather</title> | |
<style> | |
body, html { | |
background: #05a; | |
color: #fff; | |
font-family: monospace; | |
} | |
</style> | |
</head> | |
<body> | |
<% for(var i = 0; i < list.length; i++ ) { %> | |
<%= list[i].dt_txt %><br /> | |
<%= list[i].weather[0].main %><br /><hr /> | |
<% } %> | |
</body> | |
</html> |
This file contains hidden or 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 express = require('express'); | |
var app = express(); | |
var http = require('http').Server(app); | |
var path = require('path'); | |
var redis = require("redis"); | |
var client = redis.createClient(); | |
var request = require('./request'); | |
// tell express to use EJS templating | |
app.set('view engine', 'ejs'); | |
app.get('/', function(req, res){ | |
// set some data variables to use within the template | |
client.get("html", function(err, reply) { | |
if(err || reply == null) { | |
request.fetch("api.openweathermap.org", "/data/2.5/forecast?q=Vancouver,ca&mode=json", function(response) { | |
console.log("Fetched weather data from external site."); | |
var data = JSON.parse(response); | |
res.render(path.join(__dirname, 'caching.ejs'), data, function(err, html) { | |
client.set("html", data); | |
client.expire("html", 10); | |
last_fetch = Date.now(); | |
res.send(html); | |
}); | |
}); | |
} else { | |
res.send(reply); | |
} | |
}); | |
}); | |
http.listen(8888, function(){ | |
console.log('listening on *:8888'); | |
}); | |
app.use(express.static(__dirname)); |
This file contains hidden or 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
rwx rwx rwx | |
111 111 111 | |
rwx r-x r-- | |
111 101 100 | |
100 = ? | |
| | |
2^0 = 1 | |
| | |
2^1 = 2 | |
| | |
2^2 = 4 | |
100 in binary = 5 in decimal | |
rwx r-x r-- | |
111 101 100 | |
7 5 4 | |
chmod 754 filename.js | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment