Skip to content

Instantly share code, notes, and snippets.

@glynnbird
glynnbird / mangofilters.md
Last active May 31, 2022 15:00
Mango filter syntax

Currently Mango indexes are defined by feeding a list of fields to the /db/_index endpoint.

{
  "fields": ["address.city", "timestamp", "email"],
  "type": "json"
}

Cloudant also allows Lucene-powered indexes to be created in a similar way, this time providing an array of objects defining the attributes to index and their data types:

@glynnbird
glynnbird / getPartitions.js
Created May 25, 2020 07:19
Find list of CouchDB partition keys in small batches
const nano = require('Nano')(process.env.COUCH_URL)
const db = nano.db.use('pq')
// get list of partition keys
// Parameters:
// - startPartition - the last partition key you know about
// - limit - number of partition keys to getch
// Returns:
// - an array of partition keys
const getPartitions = async (startPartition = '', limit = 10) => {
@glynnbird
glynnbird / cloudant-query-pagination.md
Last active January 10, 2019 15:20
Using Pagination with Cloudant Query

Let's say we want to query a data set and get paginated result sets. In this example we're going to query a set of cities of the world, looking for those based in the USA. Our query is:

{ 
  selector: { country: 'US'}, 
  limit: 50
}

The Node.js to perform this search is as follows:

@glynnbird
glynnbird / block5a.sh
Created November 8, 2018 12:53
block5a.sh
sqlite> SELECT dispatchAddress_town as town, SUM(total)
FROM mystore
GROUP BY 1
ORDER BY 2
DESC LIMIT 10;
town SUM(total)
---------- ----------
Newport 41067.81
Linlithgow 27923.21
@glynnbird
glynnbird / drummer-sample-file.js
Last active August 31, 2017 09:50
Drummer sample file
{
"sequenceLength": "16",
"sequence": {
"kicka": [true, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false],
"kickb": [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false],
"snarea": [false, false, false, false, true, false, false, true, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false],
"snareb": [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false],
"rim": [false, false, f
@glynnbird
glynnbird / b.txt
Created April 26, 2017 10:52
Morning at the Window by T.S. Eliot
Morning at the Window
T.S. Eliot
They are rattling breakfast plates in basement kitchens,
And along the trampled edges of the street
I am aware of the damp souls of housemaids
Sprouting despondently at area gates.
The brown waves of fog toss up to me
Twisted faces from the bottom of the street,
@glynnbird
glynnbird / a.txt
Created April 26, 2017 10:52
Morning at the Window by T.S. Eliot
Morning at the Window
T.S. Eliot 1888-1965
They are rattling breakfast plates in basement kitchens,
And along the trampled edges of the street
I am aware of the damp souls of housemaids
The brown waves of fog toss up to me
Twisted faces from the bottom of the street,
And tear from a passer-by with muddy skirts
@glynnbird
glynnbird / gettingstarted.md
Last active April 5, 2017 14:55
Ethereum getting started guide

On your new Ubuntu machine

Install solc and ethereum

sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum
sudo apt-get install solc
@glynnbird
glynnbird / deploy.sh
Last active March 21, 2017 16:47
My house temperature deployment script
#!/bin/bash
# create package encapsulating the environment variables
wsk package update alexa --param url "$CLOUDANT_URL" --param dbname "$CLOUDANT_DBNAME"
# add action to the package and make it web enabled
wsk action update alexa/myhousetemperature myhousetemperature.js -a web-export true
@glynnbird
glynnbird / myhousetemperature.js
Last active March 24, 2017 19:41
Alexa Skill to fetch latest house temperature reading from Cloudant
var main = function(msg) {
// check for mandatory parameters
if (!msg.url || !msg.dbname) {
return new Error('url and dbname are required');
}
// form Cloudant URL
var url = msg.url + '/' + msg.dbname + '/_design/fetch/_view/byDate?limit=1&reduce=false&descending=true';
var request = require('request');