Skip to content

Instantly share code, notes, and snippets.

View tejacques's full-sized avatar

Tom Jacques tejacques

  • Tinder
  • San Francisco Bay Area
View GitHub Profile
#include <type_traits>
template <typename...TArgs>
struct TypeList {};
// Assume TElement is not in the list unless proven otherwise
template < typename TElement, typename TList >
struct ContainsType {
static constexpr bool value = false;
};
@tejacques
tejacques / TypedBuilder.cpp
Last active August 10, 2016 01:27
TypeSafe object loader
#include <stdio.h>
#include <vector>
using std::vector;
enum UserFlags {
BASICS = 0x1,
LOCATION = 0x2
};

Geo sharding

Shard Space

Like redis cluster, we'll use a shard space of 2^14 = 16384. Essentially what this means is that we'll take our entire geo area, and split it into 16384 segments of approximately equal entries.

Each instance will be responsible for any number of segments, typically a cluster of segments that are geographically close.

Searches

Properties:

  • Highly efficient schema-driven RPC calls
  • Session-Aware Metrics
  • Standard reporting for services about their interfaces
  • Registration with membership/load balancing servers which spread requests and merge responses
    • One such load balancer is the router service, which registers a regular-like expression (trie routing)
    • Another such load balancer is data/query routing service -- think top level of a GraphQL API. It needs to communicate with other services to generate the data.
    • Should work isomorphically, client-side bundled multiple routes, server forwards routes
  • Should support in-process communication as well, which also live/hot updates (at least in supported languages). This can be accomplished by not saving stateful objects, but instead communicating to services over interfaces.

IDL:

  • Creates an Avro-like Schema
  • Desn't require labeling field location as in Thrift / Protocol Buffers
  • Compiler to generate output boilerplate code in multiple languages
  • Runtime library for supported languages which boilerplate code will use (targeting C++, Java, Python, JavaScript, TypeScript, C#, Kotlin, Scala)
  • Supports storing data in Array of Struct (Row) or Struct of Array format (Column) per record type
  • Allows Specifying RPC calls
  • Annotations for optional implementation details
  • Inheritance
/**
* I'd like to have a router with semantics that work like this
* Pros:
* - Named routes
* - Type Safe routing (with TypeScript)
* - Links are not strings so refactoring/changing them is trivial
* - Relative links are possible
*
* Cons:
* - Verbose links
@tejacques
tejacques / HOCBaseRender.tsx
Last active May 2, 2022 13:05
React Higher Order Components in TypeScript
import * as React from 'react';
import { Component } from 'react';
export default function HOCBaseRender<Props, State, ComponentState>(
Comp: new() => Component<Props & State, ComponentState>) {
return class HOCBase extends Component<Props, State> {
render() {
return <Comp {...this.props} {...this.state}/>;
}
}
function identity(x) {
return x;
}
function fp<T1, T2> (
transform: (x: T1) => T2
): (x: T1) => T2;
function fp<T1, T2, T3> (
transform1: (x: T1) => T2,
var testFn = function() {};
testFn.prototype.test1 = function() {
console.log('test1');
};
testFn.prototype.test2 = function() {
console.log('test2');
};
let wrappable = {
'object': true,
'function': true
};
let autowrapSymbol = '@@autowrap';
function wrap(fn) {
console.log('wrapping function call');
let wrapped = function() {