Skip to content

Instantly share code, notes, and snippets.

@derickson
derickson / stddev.js
Created March 11, 2014 14:32
standard deviation MongoDB aggregation pipline using method from http://en.wikipedia.org/wiki/Standard_deviation#Rapid_calculation_methods
// standard deviation MongoDB aggregation pipline
// using method from http://en.wikipedia.org/wiki/Standard_deviation#Rapid_calculation_methods
var parts = db.stat.aggregate( { $group: { _id: null,
s0: {$sum:1},
s1:{$sum:"$stat"},
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})
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
derickson / videogame2ES.py
Last active August 29, 2015 14:25
Experiment, pulling google spreadsheet data into ES
## Dependencies in order for this to work
## 1) google spreadsheet lib: https://github.com/burnash/gspread
## pip install gspread
## 2) oauth2 lib: http://gspread.readthedocs.org/en/latest/oauth2.html
## pip install oauth2client
## 3) create a "service account" in your google api console following the instructions from the oauth2 lib above
@derickson
derickson / alias_filters.sense
Last active August 29, 2015 14:26
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
DELETE /foo
PUT /foo
{
"settings": {
"number_of_replicas": 0,
"number_of_shards": 1
},
"mappings": {
"people": {
@derickson
derickson / config.xqy
Created December 10, 2011 21:42
Mobile Shakespeare Tutorial Part 1
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
derickson / header.html
Created December 12, 2011 03:51
Mobile Shakespeare Tutorial Part 2
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href='http://fonts.googleapis.com/css?family=Aguafina+Script|Vast+Shadow' rel='stylesheet' type='text/css'/>
<link rel="stylesheet" href="/css/mobshake-jm.min.css"/>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0rc2/jquery.mobile.structure-1.0rc2.min.css"/>
<link rel="stylesheet" href="/css/mobshake.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0rc2/jquery.mobile-1.0rc2.min.js"></script>
@derickson
derickson / config-snip.xqy
Created December 17, 2011 04:55
Mobile Shakespeare Tutorial Part 3
<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>
@derickson
derickson / circles.xqy
Created January 6, 2012 04:49
GeoReverseQuery
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
derickson / event.xml
Created January 10, 2012 05:33
XQuery Choropleth
<?xml version="1.0" encoding="UTF-8"?>
<event>
<name>Bethesda</name>
<point>38.9846520, -77.0947092</point>
</event>