Skip to content

Instantly share code, notes, and snippets.

View johnlpage's full-sized avatar

John Page johnlpage

  • MongoDB Inc.
  • Glasgow
View GitHub Profile
@johnlpage
johnlpage / 1-setup-server.md
Last active December 8, 2015 13:19
Data Loading and Aggregation demo in MongoDB

#Start a machine use any method you like here, I'm doing it from the command line 40 cores, 120GB RAM, SSD with 8,500 IOPS (SAN) - Amazon linux (Centos)

ec2-run-instances ami-a10897d6 -t m4.10xlarge -g jlp -k john_page_demos -b "/dev/xvdb=:725:true:io1:8500"

#Log on

ssh -L 27017:localhost:27017 -i <your public key>.pem ec2-user@<your ip address>

#Set up disk

@johnlpage
johnlpage / gist:2e8bd55ed195cccd4af7cea718f1c640
Last active February 25, 2024 05:26
Examples for MongoDB Atlas Data API Video
ENDPOINT
--------
https://data.mongodb-api.com/app/data-amzuu/endpoint/data/beta
API KEY
--------
0vaT8d5Vh9cgvm3KdIQJWkl5M8alZgnoOczmApFlWVTMqisg24QWrUfMS0wkQ5Sj

Quick Oracle 18 XE setup for AWS

These instructions are a quick and simple way to set up Oracle for experimenting - it is no no way fit for production use. This assumes familiarity with Amazon EC2 - you could also use RHEL 7.9 installed another way but I have not tested that.

Start an EC2 Instance in a region of your choice (Ideally the same one where you will be running MongoDB Atlas). Oracle XE has limitation on hardware and data size so it should be

  • 2 CPU, 4GB RAM (t3.medium instance)
  • OS: RHEL 7.9 64 bit (RHEL-7.9_HVM-20211005-x86_64-0-Hourly2-GP2 in COmmunity AMIs)
  • 25GB gp3 root disk (Change on Add Storage screen from 10GB gp2)
//Convert fields to a string of digits and dots
var s={$reduce: {input: ["$x","$y","$s"],initialValue:"",in: {$concat:["$$value",{$toString:"$$this"},"."]}}}
var mx = {$pow:[227,{$mod:[{$add:["$$this",1]},6]}]}
//Iterate it doing iv=56781234 ; iv = (iv + 227^(i%6)*(s[i]+1))%1048576
//20 bit hash - can increase
var c={$reduce: {input: {$range : [0,{$strLenCP:"$$s"}]},initialValue:56781234,
in: {$mod: [{$add:["$$value",{$multiply:[mx,{$add:[1,{$convert:{to:"int",onError:10,
input:{$substrCP:["$$s","$$this",1]}}}]}]}]},1048576]}}}
var cksum = { $let : { vars: { s: s}, in:c }}
var validator = { $expr : { $eq : [ "$cksum", cksum]},$jsonSchema: { required: ["x","y","s","cksum"]}}
doc = {_id: "test", x:1,y:1,s:5.5}
try { db.readonlyfields.insertOne( doc) } catch(e) {print(e.errmsg)}
Document Failed validation
var sign = (doc,fields) => {
let toSign=""
fields.forEach(f => { toSign += parseFloat(doc[f]) + "." } )
toSign = toSign.replace(/NaN/,'.')
print(`Signing: ${toSign}`)
iv = 56781234
for(c=0;c<toSign.length;c++) {
v = parseInt(toSign[c])
if(isNaN(v)) v=10; //Dots etc
v += 1; //No point multiplying 0 by anything
{
"errInfo": {
"failingDocumentId": "test",
"details": {
"operatorName": "$and",
"clausesNotSatisfied": [
{
"index": 0,
"details": {
"operatorName": "$expr",
[{
$match: {
reading: { $gt: 1000, $lt: 40000 }
}
}, {
$setWindowFields: {
partitionBy: "$type",
sortBy: { date: 1 },
output: {
hourago: {
[{
$group: {
_id: {
date: {
$dateTrunc: {date: "$date", unit: "day"}
},
type: "$type"
},
max: { $max: "$reading" },
min: { $min: "$reading" }
from bluepy.btle import Scanner, DefaultDelegate, Peripheral
from pprint import pprint
import time
import pymongo
import datetime
TEMPERATURE_SERVICE_UUID = "e95d6100-251d-470a-a062-fa1922dfa9a8"
TEMPERATURE_CHARACTERISTIC_UUID = "e95d9250-251d-470a-a062-fa1922dfa9a8"