Skip to content

Instantly share code, notes, and snippets.

View pcattori's full-sized avatar

Pedro Cattori pcattori

View GitHub Profile

Our job as framework authors is to strike a balance b/w prescribing a solution and scaling a solution from small apps to large apps.

We should only strongly prescribe when:

  1. There's already a clear winner (TypeScript)
  2. when the whole team believes should be the one obvious way to do something
import { route } from "remix"

/*
@pcattori
pcattori / router.ts
Last active February 9, 2023 19:15
granular route update APIs for RR
let cloneDataRoutes = (
routes: AgnosticDataRouteObject[]
): AgnosticDataRouteObject[] => {
return routes.map((route) => {
if (route.children === undefined) return route;
return {
...route,
children: cloneDataRoutes(route.children),
};
});
@pcattori
pcattori / builder-first.py
Created July 31, 2018 19:43
`builder-first` python implementation
import unifyapi.v1 as api
unify = api.Client()
# get all datasets by name
matching_datasets = [d for d in unify.datasets.get() if d.name == 'myDataset'] # client convenience method: unify.datasets.find_by_name(...)
assert(len(matching_datasets) == 1)
dataset = matching_datasets[0]
# 1. Update Dataset records
@pcattori
pcattori / continuous-operation-of-categorization-project.py
Last active July 31, 2018 16:12
Model-centric API client design for Categorization workflow
import unifyapi.v1 as api
unify = api.Client() # can specify host/port if needed, but by default localhost/9100
project = unify.projects.named('Automotive parts classification 2018') # some collection models offer alternative ways to lookup instances, e.g. by name
source_datasets = [
'car_parts_2018.csv',
'SteeringWheelSupplierINC_parts.csv',
]
# option 1: all models
project = unify.projects.getByName('Customers Q4 2018') # returns Project model
ud1 = project.unified_dataset # returns Dataset model.
# Note: could have unified_dataset be a dynamic property or a method... (`.unified_dataset` vs `.unified_dataset()`)
ud2 = unify.projects.getByName('Suppliers Q3 2017').unified_dataset
@pcattori
pcattori / gist:2bb645d587e45c9fdbcabf5cef7a7106
Last active February 20, 2022 00:01
relay-style cursor-based pagination capable of filtering/sorting for SQL
import { Base64 } from 'js-base64'
import { Op } from 'sequelize'
import { fromGlobalId } from 'graphql-relay'
// https://github.com/graphql/graphql-relay-js/issues/94#issuecomment-232410564
const effectiveOrder = ({ last }, orderBy) => {
/* adds `id ASC` to end of `ORDER BY` if `id` is not already in the `ORDER BY` clause
flips `ASC` to `DESC` (and vice-versa) if pagination arg `last` is defined
*/