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
| // Copyright Chris Anderson 2011 | |
| // Apache 2.0 License | |
| // jquery.couchLogin.js requires jquery.couch.js | |
| // | |
| // Example Usage (loggedIn and loggedOut callbacks are optional): | |
| // $("#mylogindiv").couchLogin({ | |
| // loggedIn : function(userCtx) { | |
| // alert("hello "+userCtx.name); | |
| // }, | |
| // loggedOut : function() { |
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>Tiny CouchApp</title></head> | |
| <body> | |
| <h1>Tiny CouchApp</h1> | |
| <form id="new_message"> | |
| <label for="message">Message:</label> | |
| <input type="text" name="message" value=""> | |
| <p><input type="submit" value="Save →"></p> | |
| </form> |
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
| rainPain = function(temp, cip) { | |
| if (temp < 39) { | |
| console.log ("too cold!") | |
| } else if (temp<80 && cip){ | |
| console.log("ouch") | |
| } else { | |
| console.log("time to walk the dogs") | |
| } | |
| } | |
| rainPain(75, true) |
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> | |
| <!-- This should be the simplest possible jQuery based CouchApp. Install by uploading to a design document in Futon or putting in _attachments/index.html and running `couchapp push` --> | |
| <head><title>Tiny CouchApp</title></head> | |
| <body> | |
| <h1>Tiny CouchApp</h1> | |
| <ul id="databases"></ul> | |
| </body> | |
| <script src="/_utils/script/jquery.js"></script> | |
| <script src="/_utils/script/jquery.couch.js"></script> |
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
| function(ks, vs, rr) { | |
| // values are discarded by reduce | |
| // todo: configurable key function, for complex queries | |
| var fk, lk; | |
| function uniqCount(keys) { | |
| var count = 0, obj = {}; | |
| for (var i=0; i < keys.length; i++) { | |
| if (!obj[keys[i]]) { | |
| count++; | |
| obj[keys[i]] = true; |
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
| require 'rubygems' | |
| require 'garb' | |
| # couchrest is only required because it makes the dates to_json into | |
| # something javascript can parse. | |
| require 'couchrest' | |
| class OpenStruct | |
| def to_json | |
| table.to_json | |
| end |
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
| function(seq, req) { | |
| var min = 0, term, count, row | |
| , i, top = parseInt(req.query.top), match = []; | |
| while (row = getRow()) { | |
| term = row.key[0]; | |
| count = row.value; | |
| if (match.length < top) { | |
| match.push([term, count]); | |
| } else { | |
| if (count > min) { |
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
| require 'digest/md5' | |
| # usage: run this in the root directory of your iTunes Music folder, or wherever, and pipe the output to a file | |
| # next, pipe the output of that file through `sort` to a new file | |
| # now, use the next script on that file | |
| ls = Dir['**/*'] | |
| ls.each_with_index do |f, i| | |
| STDERR.puts ls.length - i if (i % 100 == 0) |
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
| // Copyright J. Chris Anderson 2007 | |
| // Retain this notice. | |
| // Released under the LGPL 2.1 | |
| // http://creativecommons.org/licenses/LGPL/2.1/ | |
| XSPF = { | |
| XMLfromString: function(string) { | |
| if (window.ActiveXObject) { | |
| var doc = new ActiveXObject("Microsoft.XMLDOM"); | |
| doc.async = "false"; |
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
| require 'lib/yajl/http_stream' | |
| require 'uri' | |
| uri = URI.parse('http://jchrisa.net/toast/_changes') | |
| Yajl::HttpStream.get(uri) do |hash| | |
| # will take a few seconds, since the response is a single ~4MB JSON string | |
| # if the response was a bunch of individual JSON strings, this would be fired | |
| # for every string parsed off the stream, as they were parsed | |
| puts hash.inspect | |
| end |