Skip to content

Instantly share code, notes, and snippets.

View myhrvold's full-sized avatar
🏠
Working from home

Conor L. Myhrvold myhrvold

🏠
Working from home
View GitHub Profile
@myhrvold
myhrvold / rideconstraints_ex.txt
Last active May 14, 2016 05:40
Fifth Example for Ride Policies Uber for Business Article Raw
(minuteOfDay >= 1260 && minuteOfDay <= 1439 && contains([3,4,5], dayOfWeek)) ||
(minuteOfDay >= 0 && minuteOfDay <= 240 && contains([4,5,6], dayOfWeek)) &&
(distance(originLatitude, originLongitude, 52.924345, -1.216398) <= 400)
@myhrvold
myhrvold / input_ex.json
Last active May 14, 2016 05:34
Fourth Example for Ride Policies Uber for Business Article
{
"components": [
{
"type": "geo",
"origins": [
{
"type": "originDistance",
"latitude": 52.924345,
"longitude": -1.216398,
"distance": 400
@myhrvold
myhrvold / rule_ex_eval2.js
Created May 14, 2016 05:29
Third Example for Ride Policies Uber for Business Article
var evaluateRule = require('./uber-rule-evaluator');
var isInteger = "floor(x) === x";
var floatFact = {
x: 10.5,
floor: Math.floor
};
var intFact = {
x: 10,
@myhrvold
myhrvold / rule_ex_eval.js
Created May 14, 2016 05:27
Second Example for Ride Policies Uber for Business Article
var evaluateRule = require('./uber-rule-evaluator');
var rule = "x > y + z";
var facts = {
x: 30,
y: 15,
z: 10
};
console.log(evaluateRule(rule, facts));
// true
@myhrvold
myhrvold / ruleengine_ex.js
Created May 14, 2016 05:25
First Example for Ride Policies Uber for Business article
var esprima = require('esprima');
var evaluate = require('static-eval');
module.exports = function evaluateRule(rule, fact) {
var ruleAST = esprima.parse(rule);
return evaluate(ruleAST.body[0].expression, fact);
}
@myhrvold
myhrvold / ringpopexample.js
Created February 16, 2016 20:29
Handle-or-Forward Pattern Example for Ringpop
module.exports = function handleOrForward(ringpop, key, req, res, arg2, arg3, handle) {
var dest = ringpop.lookup(key);
if (dest === ringpop.whoami()) {
// Handle request on local node
handle(ringpop, key, res, arg2, arg3);
return;
}
// Forward request
var channel = ringpop.channel;
@myhrvold
myhrvold / serviceexample.thrift
Last active February 16, 2016 20:08
Statement Client Thrift Service Example in Pseudocode
service StatementClient {
// Service: "I'm making weekly statements for last week. Do any of your users want any?"
// Client: "Yes, I want statements for users uuid1, uuid2, …"
getStatementCandidates(request);
// Service: "Okay, what does user uuid1 need in its statement for last week?"
// Client: "All this information …"
getStatementCandidateDetails(request);
@myhrvold
myhrvold / schemalass_triggers_example.py
Last active February 22, 2016 18:52
Schemaless Triggers Example: Simplified Asynchronous Billing
# We instantiate a client for talking with the Schemaless instance.
schemaless_client = SchemalessClient(datastore='mezzanine')
# We register the bill_rider function for the BASE column.
@trigger(column='BASE')
def bill_rider(row_key):
# row_key is the UUID of the trip
status = schemaless_client.get_cell_latest(row_key, 'STATUS')
@myhrvold
myhrvold / driver_partner_index.yaml
Created February 16, 2016 19:47
Driver Partner Index Example in YAML Format
table: driver_partner_index # Name of the index.
datastore: trips # Name of the associated datastore
column_defs:
– column_key: BASE # From which column to fetch from.
fields: # The fields in the cell to denormalize
@myhrvold
myhrvold / animalexample.thrift
Created February 16, 2016 19:43
Thrift Example: Service-Oriented Architecture at Uber Engineering
struct Animal {
1: i32 id
2: string name
3: string sound
}
exception NotFoundException {
1: i32 what
2: string why
}