Skip to content

Instantly share code, notes, and snippets.

@drsm79
drsm79 / gist:1223744
Created September 17, 2011 08:04
jsonised cities of the world
{"latitude": "42.40N", "country": "Bulgaria", "longitude": "023.18E", "city": "Sofia"}
{"latitude": "50.06N", "country": "Czech Republic", "longitude": "014.26E", "city": "Prague"}
{"latitude": "15.20N", "country": "Eritrea", "longitude": "038.58E", "city": "Asmera"}
{"latitude": "59.22N", "country": "Estonia", "longitude": "024.48E", "city": "Tallinn"}
{"latitude": "18.08S", "country": "Fiji", "longitude": "178.25E", "city": "Suva"}
{"latitude": "60.08N", "country": "Finland", "longitude": "025.00E", "city": "Helsinki"}
{"latitude": "06.09N", "country": "Iceland", "longitude": "021.51W", "city": "Reykjavik"}
{"latitude": "28.37N", "country": "India", "longitude": "077.13E", "city": "New Delhi"}
{"latitude": "53.20N", "country": "Ireland", "longitude": "006.15W", "city": "Dublin"}
{"latitude": "41.48N", "country": "Italy", "longitude": "012.36E", "city": "Rome"}
@drsm79
drsm79 / cities.py
Created September 17, 2011 08:07
Cities parsing script
# encoding: utf-8
"""
Quick script to dump out the long/lat of most of the capital cities in the world (I removed ones with unicode characters).
"""
import csv
import json
cities = u"""Bulgaria,Sofia,42.40N 023.18E
Czech Republic,Prague,50.06N 014.26E
function(doc){
index("default", doc._id);
if(doc.min_length){
index("min_length", doc.min_length, {"store": "yes"});
}
if(doc.diet){
index("diet", doc.diet, {"store": "yes"});
}
if (doc['class']){
index("class", doc.['class'], {"store": "yes"});
@drsm79
drsm79 / gist:3143589
Created July 19, 2012 12:47
Non-trivial Flask blueprint
from flask import Blueprint, current_app, request, jsonify
users = Blueprint('users', __name__)
@users.route('/<username>', methods=['GET', 'POST', 'PUT', 'DELETE'])
def profile(username):
messages = {'GET': 'info about %s' % username,
'POST': 'create account for %s' % username,
@drsm79
drsm79 / gist:3143612
Created July 19, 2012 12:51
Flask app using blueprints
from flask import Flask, url_for
from user_api import users
app = Flask(__name__)
app.register_blueprint(users, url_prefix='/users')
if __name__ == "__main__":
app.run(debug=True)
@drsm79
drsm79 / Result.txt
Created July 19, 2012 22:39
Bookmarking test
$ python bookmark_test.py
all animals: [u'llama', u'elephant', u'lemur', u'zebra', u'badger', u'aardvark', u'giraffe', u'panda']
[u'llama', u'elephant']
g1AAAAETeJzLYWBgYMlgTWFQSElKzi9KdUhJMtLLTS3KLElMT9VLzskvTUnMK9HLSy3JAapkymMBkgwNQOr____7sxL53ew_MIBBIiOqKcYETTkAMeV_ViKrm_1vccUGkCkMqKYY4jElyQFIJtWDTWBys7-8uIoBiwkmeExIZEiyhzngxR0miDeyAOI8V1I
[u'zebra', u'badger']
g2wAAAABaAVkACBkYmNvcmVAZGI0Lm1lcml0YWdlLmNsb3VkYW50Lm5ldGwAAAACYQBiP____2phBUY_6NwCAAAAAGEDag
[]
g2o
[u'llama', u'elephant', u'lemur', u'zebra']
g1AAAAETeJzLYWBgYMlgTWFQSElKzi9KdUhJMtLLTS3KLElMT9VLzskvTUnMK9HLSy3JAapkymMBkgwNQOr____7sxL53ew_MIBBIiPxpiQyJNkD9WclsrrZv7jDBNbOjKrdkKAjDkAcATHlt7hiA8gUBuJNSXIAkkn1YBOY3OwvL64Cu4MhCwApB1dQ
@drsm79
drsm79 / gist:3198935
Created July 29, 2012 13:48
Installing situp
git clone git://github.com/drsm79/situp.git
cd situp
export PYTHONPATH=$PYTHONPATH:$PWD
chmod u+x situp.py

export PATH=$PATH:$PWD

@drsm79
drsm79 / gist:3198994
Created July 29, 2012 13:56
Creating a view with situp

To create my_view in $PWD/_design/my_design run:

situp.py view -d my_design my_view

This produces a skeleton map.js and reduce.js in $PWD/_design/my_design/views/my_view/. If you want to use a built-in reduce (sum|count|stats) run:

situp.py view -d my_design my_view --count

@drsm79
drsm79 / bundle.config.json
Created August 6, 2012 14:36
Bundle task
bundle: {
// Files to bundle up that aren't css/js managed by release. Copied into
// same directory structure
files: ['*.html'],
// Folders to bundle up that aren't managed by release. Copy files and
// folders from src (key) to destination (value), relative to the
// destination parameter.
folders: {'assets/img':'assets/img', 'dist/release':''},
destination: 'bundle'
}
map:
function(doc) {
for (key in doc){
emit(key, 1);
}
}
reduce: