Skip to content

Instantly share code, notes, and snippets.

View dch's full-sized avatar
🛋️

Dave Cottlehuber dch

🛋️
View GitHub Profile
$(function() {
//run the accordion plugin, set height of sections to height of content
$("#accordion").accordion({ autoHeight: false });
});
;(function($) {
//write new sammy application
var app = new Sammy.Application(function() {
with(this) {
//corresponds to routes such as #/section/1
get('#/section/:section_id', function() { with(this) {
function isPointInPoly(poly, pt) {
for(var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i)
((poly[i][1] <= pt.y && pt.y < poly[j][1]) || (poly[j][1] <= pt.y && pt.y < poly[i][1])) && (pt.x < (poly[j][0] - poly[i][0]) * (pt.y - poly[i][1]) / (poly[j][1] - poly[i][1]) + poly[i][0]) && (c = !c);
return c;
}
isPointInPoly([[1, 1], [5, 1], [5, 5], [1, 5]], {x: 2, y: 2}); //true
isPointInPoly([[1, 1], [5, 1], [5, 5], [1, 5]], {x: 100, y: 100}); //false
@anandology
anandology / coucheval.js
Created November 4, 2010 09:39
node.js script to process couchdb output
#!/usr/bin/env node
// Sample usage:
//
// $ curl -s 'http://127.0.0.1:15984/seeds/_all_docs?limit=10&include_docs=true' | coucheval.js 'console.log(JSON.stringify(row.doc));'
//
var carrier = require('carrier');
var stdin = process.openStdin();
@davisp
davisp / couch-node.ini
Created November 5, 2010 23:45
Configuring CouchDB (trunk) to have a node.js handler.
; Just drop this in /etc/couchdb/local.d/ and then
; start CouchDB normally.
; Here couch_node can be anything as long as it's uniq.
[os_daemons]
couch_node = /Users/davisp/tmp/couch-node.js
@Pablosan
Pablosan / ec2_instance_create_and_setup.sh
Created January 30, 2011 23:37
A bash script that will set up a new EC2 instance and ssh into it.
#!/bin/bash
# Authorize TCP, SSH & ICMP for default Security Group
#ec2-authorize default -P icmp -t -1:-1 -s 0.0.0.0/0
#ec2-authorize default -P tcp -p 22 -s 0.0.0.0/0
# The Static IP Address for this instance:
IP_ADDRESS=$(cat ~/.ec2/ip_address)
# Create new t1.micro instance using ami-cef405a7 (64 bit Ubuntu Server 10.10 Maverick Meerkat)
@huyng
huyng / reflect.py
Created February 7, 2011 17:57
A simple echo server to inspect http web requests
#!/usr/bin/env python
# Reflects the requests from HTTP methods GET, POST, PUT, and DELETE
# Written by Nathan Hamiel (2010)
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from optparse import OptionParser
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
@fdmanana
fdmanana / gist:832610
Created February 17, 2011 20:27
The CouchDB replicator database

1. Introduction to the replicator database

A database where you PUT/POST documents to trigger replications and you DELETE to cancel ongoing replications. These documents have exactly the same content as the JSON objects we used to POST to /_replicate/ (fields "source", "target", "create_target", "continuous", "doc_ids", "filter", "query_params".

Replication documents can have a user defined "_id". Design documents (and _local documents) added to the replicator database are ignored.

The default name of this database is _replicator. The name can be changed in the .ini configuration, section [replicator], parameter db.

2. Basics

@jchris
jchris / index.html
Created April 27, 2011 16:54
jQuery CouchDB Hello World - to use this script, create the map view in futon and click Save As, then upload index.html as an attachment to _design document created with the view. browse to index.html to run the app.
<!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 &rarr;"></p>
</form>
@dch
dch / compact_data.erl
Created June 24, 2011 01:57
useful examples using hovercraft
-module(compact_data).
-author('bob@cloudant.com').
-export([test_id_btree/1, test_db/4, test_view/1, test_view/4]).
-include("couch_db.hrl").
-define(ADMIN_USER_CTX, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
test_id_btree(N) ->
@msmith
msmith / couchdb-ec2-install.sh
Created August 25, 2011 17:26
Set up CouchDB on EC2
#!/bin/bash
#
# This script installs and configures couchdb on a fresh Amazon Linux AMI instance.
#
# Must be run with root privileges
# Tested with Amazon Linux AMI release 2011.02.1.1 (ami-8c1fece5)
#
export BUILD_DIR="$PWD"