This file contains 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
{ | |
views: { | |
gender: { | |
map: function(doc){ | |
var lib = require('/views/lib/transform') | |
, key_value = lib.gender(doc); | |
emit(key_value[0], key_value[1]); | |
} | |
}, |
This file contains 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(doc){ | |
// handle a custom format using methods in the date object | |
var format = "{getFullYear}/{getMonth}/{getDate}", | |
date = new Date(doc.created_at), | |
// use a regular expression to replace parts of our format string | |
formatted_date = format.replace(/\{(\w+)\}/g, function(str, func){ | |
var time = date[func](); | |
// if `func` is `getMonth` we must offset by one | |
if(func === 'getMonth'){ | |
time += 1; |
This file contains 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(head, req){ | |
var i, | |
x, | |
results = {}, | |
headers = {}, | |
csv = []; | |
while(x = getRow()){ | |
(function(row){ | |
var result = results[JSON.stringify(row.key)] || {}; | |
for(i in row.value){ |
This file contains 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
#!/usr/bin/perl | |
# CouchDB Tunnel Tool for MacOS X and Linux | |
# Copyright (c) 2010 Linode, LLC | |
# Author: Philip C. Paradis <[email protected]> | |
# Modifications: Sam Kleinman <[email protected]> | |
# Usage: couchdb-tunnel.pl [start|stop] | |
# Access a CouchDB database instance by way of an SSH tunnel. | |
## |
This file contains 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 couchapp = require('couchapp'), | |
path = require('path'); | |
ddoc = { | |
_id: '_design/app', | |
rewrites: [{ | |
from: '', | |
to: '/index.html' | |
},{ | |
from: '*', |
This file contains 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
{ | |
// name of the design doc | |
_id: '_design/relations', | |
views: { | |
lib: couchapp.loadFiles(__dirname + '/../lib'), | |
// collate entity relations using | |
collate: { | |
map: function (doc) { | |
var deref = require('views/lib/index').deref, | |
relation = deref[doc.type]; |
This file contains 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
import random | |
prefix = [ | |
'do', | |
'grow', | |
'edge', | |
'next', | |
'build', | |
'sleep', | |
'play', |
This file contains 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
/* | |
* Given array `records` and function `fn` | |
* returns an array where | |
* any records with duplicate `fn(record)` values | |
* are omitted. | |
* | |
* Runs in O(n) where n is records.length | |
*/ | |
function remove_duplicates (records, fn) { | |
var uniques = {}, |
This file contains 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
# _all_docs | |
curl http://localhost:5984/eggchair/_all_docs?include_docs=true | jq -c ".rows[] | .doc" | dat --json | |
# _changes | |
curl http://localhost:5984/eggchair/_changes?include_docs=true | jq -c ".results[] | .doc" | dat --json |
This file contains 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
# N.B. doesn't get maximum score: | |
# * won't get captives behind the warrior | |
# * will shoot captives at look[1] if an enemy is in look[2] | |
class Player | |
def play_turn(warrior) | |
@warrior = warrior | |
## uncomment `@max_health` and `@prev_health` on level 3 | |
# @max_health ||= warrior.health # set to `1` to complete level 8 in 27 turns | |
# @prev_health ||= @max_health |