├── README.textile
├── load.sh
├── yak
├── cookie.js
├── favicon.png
├── index.html
├── jquery.min.js
├── json2.js
├── md5-min.js
├── riak.js
├── styles.css
└── yakriak.js
└── yakmr
├── mapMessageSince
├── reduceLimitLastN
└── reduceSortTimestamp
/README.textile:
--------------------------------------------------------------------------------
1 | **This repository is not maintained, use at your own risk.**
2 |
3 | h1. yakriak
4 |
5 | A simple web-based chatroom app. Designed as a proof-of-concept for Ben Black's Riak training at VelocityConf 2010.
6 |
7 | h2. Features / Problems
8 |
9 | * Everything is stored and served out of Riak. No special abstraction. Take that, couchapps!
10 | * Browser Compatibility:
11 | ** WebKit-based (Chrome, Safari)
12 | ** Firefox 3.6 and 4.0
13 | ** MSIE8, maybe 7 (tested via 8's IE7 mode)
14 | * Remembers your login credentials via unencrypted cookies (not transmitted).
15 | * Randomizes the polling interval to avoid thundering-herd effects.
16 | * Uses full-bucket map-reduce, so won't perform well at huge numbers of messages. Future work could change to use key-filters but would still incur the price of list-keys.
17 | * Your email address will be used for Gravatar, should you decide not to remain anonymous.
18 |
19 | h2. Setup
20 |
21 | # Startup Riak locally on the standard HTTP port (8098).
22 | # Join your local node to the cluster, if necessary.
23 | # Run the @load.sh@ bash script.
24 | # Visit "http://127.0.0.1:8098/riak/yak/index.html":http://127.0.0.1:8098/riak/yak/index.html
25 |
26 | h2. Learn more
27 |
28 | Read the source! The majority of the work is in @yak/yakriak.js@, and the map and reduce functions in the @yakmr/@ directory.
29 |
30 | h2. Credit where credit's due
31 |
32 | * jQuery 1.4.2 (jQuery team)
33 | * riak-javascript-client (Basho)
34 | * json2.js (Douglas Crockford)
35 | * cookie.js (Maxime Haineault, John W. Long)
36 | * md5.js (Paul Johnston)
37 |
--------------------------------------------------------------------------------
/load.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # Allow running the script and specifiying an install target
4 | # ./load.sh node-address:host
5 | if [ -n "$1" ] ; then
6 | node=$1
7 | else
8 | node="127.0.0.1:8098"
9 | fi
10 |
11 | function storeInRiak {
12 | echo "Storing $1 as $2";
13 | curl -X PUT "http://$node/riak/$1" -H "Content-Type: $2" --data-binary @$1
14 | }
15 |
16 | for file in yak/*.html; do
17 | storeInRiak $file 'text/html'
18 | done
19 |
20 | for file in yak/*.js; do
21 | storeInRiak $file 'application/javascript'
22 | done
23 |
24 | for file in yak/*.css; do
25 | storeInRiak $file 'text/css'
26 | done
27 |
28 | for file in yak/*.png; do
29 | storeInRiak $file 'image/png'
30 | done
31 |
32 | for file in yakmr/*; do
33 | storeInRiak $file 'application/javascript'
34 | done
35 |
--------------------------------------------------------------------------------
/yak/cookie.js:
--------------------------------------------------------------------------------
1 | /*
2 | cookie.js
3 |
4 | Copyright (c) 2007, 2008 Maxime Haineault
5 | (http://www.haineault.com/code/cookie-js/, http://code.google.com/p/cookie-js/)
6 |
7 | Portions Copyright (c) 2008, John W. Long
8 |
9 | Permission is hereby granted, free of charge, to any person obtaining
10 | a copy of this software and associated documentation files (the
11 | "Software"), to deal in the Software without restriction, including
12 | without limitation the rights to use, copy, modify, merge, publish,
13 | distribute, sublicense, and/or sell copies of the Software, and to
14 | permit persons to whom the Software is furnished to do so, subject to
15 | the following conditions:
16 |
17 | The above copyright notice and this permission notice shall be
18 | included in all copies or substantial portions of the Software.
19 |
20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 | */
28 |
29 | Cookie = {
30 | get: function(name) {
31 | // Still not sure that "[a-zA-Z0-9.()=|%/]+($|;)" match *all* allowed characters in cookies
32 | tmp = document.cookie.match((new RegExp(name +'=[a-zA-Z0-9.()=|%/]+($|;)','g')));
33 | if (!tmp || !tmp[0]) {
34 | return null;
35 | } else {
36 | return unescape(tmp[0].substring(name.length + 1, tmp[0].length).replace(';', '')) || null;
37 | }
38 | },
39 |
40 | set: function(name, value, expireInHours, path, domain, secure) {
41 | var cookie = [
42 | name + '=' + escape(value),
43 | 'path=' + ((!path || path == '') ? '/' : path)
44 | ];
45 | if (Cookie._notEmpty(domain)) cookie.push('domain=' + domain);
46 | if (Cookie._notEmpty(expireInHours)) cookie.push(Cookie._hoursToExpireDate(expireInHours));
47 | if (Cookie._notEmpty(secure)) cookie.push('secure');
48 | return document.cookie = cookie.join(';');
49 | },
50 |
51 | erase: function(name, path, domain) {
52 | path = (!path || typeof path != 'string') ? '' : path;
53 | domain = (!domain || typeof domain != 'string') ? '' : domain;
54 | if (Cookie.get(name)) Cookie.set(name, '', 'Thu, 01-Jan-70 00:00:01 GMT', path, domain);
55 | },
56 |
57 | // Returns true if cookies are enabled
58 | accept: function() {
59 | Cookie.set('b49f729efde9b2578ea9f00563d06e57', 'true');
60 | if (Cookie.get('b49f729efde9b2578ea9f00563d06e57') == 'true') {
61 | Cookie.erase('b49f729efde9b2578ea9f00563d06e57');
62 | return true;
63 | }
64 | return false;
65 | },
66 |
67 | _notEmpty: function(value) {
68 | return (typeof value != 'undefined' && value != null && value != '');
69 | },
70 |
71 | // Private function for calculating the date of expiration based on hours
72 | _hoursToExpireDate: function(hours) {
73 | if (parseInt(hours) == 'NaN' ) return '';
74 | else {
75 | now = new Date();
76 | now.setTime(now.getTime() + (parseInt(hours) * 60 * 60 * 1000));
77 | return now.toGMTString();
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/yak/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seancribbs/yakriak/381e3dc01ede11beebb480d288cd81d6f123bc9c/yak/favicon.png
--------------------------------------------------------------------------------
/yak/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |