Skip to content

Instantly share code, notes, and snippets.

Created April 1, 2016 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/f77e12122fd68ffa459c69b7e0ce0816 to your computer and use it in GitHub Desktop.
Save anonymous/f77e12122fd68ffa459c69b7e0ce0816 to your computer and use it in GitHub Desktop.
RethinkDB application built with Dogescript
<!DOCTYPE html>
<html>
<head>
<title>Skyla's DogeScript demo</title>
<script src="/socket.io/socket.io.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/2.0.0/handlebars.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/2.0.0/handlebars.runtime.min.js"></script>
<style>
body {
font-family: sans-serif;
}
.message img {
width: 300px;
}
.message {
margin-top: 15px;
}
#input-area {
margin-top: 25px;
}
</style>
</head>
<body>
<h1>DogeChat</h1>
<div id="messages">
</div>
<div id="input-area">
<input id="message" type="text" placeholder="enter message here">
</div>
<script id="message-template" type="text/x-handlebars-template">
<div class="message">
<div class="user">{{name}}:</div>
<div class="message">
<img src="http://dogr.io/{{message}}.png?split=false"
</div>
</div>
</script>
<script src="/wowindex.js"></script>
</body>
</html>
so rethinkdbdash
so express
so socket.io as sockio
so http
so body-parser as bodyParser
very r is plz rethinkdbdash
very app is plz express
very server is plz http.Server with app
very io is plz sockio with server
very static is plz express.static with 'public'
plz app.use with static
plz app.use with bodyParser.json()
very makeTable is plz r.tableCreate with 'dogechat'
plz r.tableList&
dose contains with 'dogechat'&
dose not&
dose and with makeTable&
dose then with much
very query is plz r.table with 'dogechat'&
dose changes
wow& query
dose then with much feed
plz feed.each with much err change
plz io.sockets.emit with 'message' change.new_val
wow&
wow&
plz app.get with '/api/fetch' much req res
plz r.table with 'dogechat'&
dose orderBy with r.desc('time')&
dose limit with 5&
dose then with much output
plz res.send with output
wow&
wow&
plz app.post with '/api/send' much req res
very doc is {name:req.body.name,message:req.body.message,time:r.now()}
plz r.table with 'dogechat'&
dose insert with doc&
dose then with much output
plz res.send with output
wow&
wow&
plz server.listen with 8000
very template is plz Handlebars.compile with $("#message-template").html()
plz io&
dose on with 'message' addMessage
such addMessage much message
very content is plz template with message
plz $("#messages").append with content
wow
such sendMessage much name text
very doc is plz JSON.stringify with {name: name, message: text}
very head is {'Content-Type':'application/json','Accept':'application/json'}
plz fetch with '/api/send' {method: 'POST', headers: head, body: doc}&
dose then with much output
plz console.loge output
wow&
wow
very username is plz prompt with 'Please enter your username'
plz fetch with '/api/fetch'&
dose then with much res
wow& res.json()
dose then with much output
plz output.map with addMessage
wow&
plz $("#message").keyup with much e
rly e.keyCode is 13
plz sendMessage with username e.target.value
e.target.value is ''
wow
wow&
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment