Skip to content

Instantly share code, notes, and snippets.

derickson / stddev.js
Created Mar 11, 2014
standard deviation MongoDB aggregation pipline using method from
View stddev.js
// standard deviation MongoDB aggregation pipline
// using method from
var parts = db.stat.aggregate( { $group: { _id: null,
s0: {$sum:1},
s2:{$sum:{$multiply:["$stat","$stat"]}} }} ).result[0];
var stddev = Math.sqrt( parts.s0 * parts.s2 - Math.pow( parts.s1, 2) ) / parts.s0
## import the necessary libraries
from io import BytesIO
from pymongo import MongoClient
import gridfs
import random
from math import ceil
## delete all versions of the file
def deleteFile(db, fs, name):
oldFile = db['fs.files'].find_one({"filename":name})
View not_indexing_fields
DELETE /storedvsunstoredtest
## notice I disable the _all text index and the index: no setting on field2
PUT /storedvsunstoredtest
"settings": {
"number_of_replicas": 0,
"number_of_shards": 3
"mappings": {
derickson /
Last active Aug 29, 2015
Experiment, pulling google spreadsheet data into ES
## Dependencies in order for this to work
## 1) google spreadsheet lib:
## pip install gspread
## 2) oauth2 lib:
## pip install oauth2client
## 3) create a "service account" in your google api console following the instructions from the oauth2 lib above
derickson / alias_filters.sense
Last active Aug 29, 2015
Quick test for Elasticsearch in sense to prove Alias filters correctly work with searches, facet term counts, and global aggregation. proves that term suggester doesn't respect alias filter
View alias_filters.sense
PUT /foo
"settings": {
"number_of_replicas": 0,
"number_of_shards": 1
"mappings": {
"people": {
derickson / config.xqy
Created Dec 10, 2011
Mobile Shakespeare Tutorial Part 1
View config.xqy
xquery version "1.0-ml" ;
(: config.xqy
This library module holds configuration
variables for the application
module namespace cfg = "http://framework/lib/config";
(: The rewrite library route configuration
derickson / header.html
Created Dec 12, 2011
Mobile Shakespeare Tutorial Part 2
View header.html
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href='|Vast+Shadow' rel='stylesheet' type='text/css'/>
<link rel="stylesheet" href="/css/mobshake-jm.min.css"/>
<link rel="stylesheet" href=""/>
<link rel="stylesheet" href="/css/mobshake.css" />
<script src=""></script>
<script src=""></script>
derickson / config-snip.xqy
Created Dec 17, 2011
Mobile Shakespeare Tutorial Part 3
View config-snip.xqy
<get path="play/:id/act/:act/scene/:scene/speech/:speech"><to>play#scene</to></get>
<get path="search"><to>search#get</to></get>
<post path="search"><to>search#get</to></post>
View circles.xqy
xquery version "1.0-ml";
(: a whole bunch of random circles to make the reverse-query harder :)
let $n := 10000
for $count in (1 to $n)
let $lat := xdmp:random(180) - 90
let $lon := xdmp:random(360) - 180
let $query-doc :=
derickson / event.xml
Created Jan 10, 2012
XQuery Choropleth
View event.xml
<?xml version="1.0" encoding="UTF-8"?>
<point>38.9846520, -77.0947092</point>