Skip to content

Instantly share code, notes, and snippets.

View micimize's full-sized avatar

Michael Joseph Rosenthal micimize

  • San Francisco, CA
View GitHub Profile
@micimize
micimize / schema_constraints_checks.py
Last active July 6, 2019 16:10
efficient goodtables constraint checks
import typing as t
from goodtables import Error, check
from tableschema.exceptions import TableSchemaException
from .schema_field import ConstraintsError, ExtensibleField
# primaryKey and unique constraints are unaccounted for here
# TODO look into optimizing unique constraint checks
@micimize
micimize / df_partition.py
Created July 6, 2019 16:12
dataflow for partitioning a resource based on a validator
"""
In dataflows, the API for operating on an entire package goes as follows:
* we define a Higher order function to take in config and context
* in that function, we define and return a function that will operate on various resources.
In this instance, that function operates on the entire datapackage. To do so it yields, in order:
* the package definition, with changes (adds the new resource)
* a generator for each resource, in the order they are defined
"""
import typing as t
@micimize
micimize / goodtables_row_inspector.py
Created August 15, 2019 01:15
Row-wise inspection for goodtables
import typing as t
from math import inf
from goodtables import Inspector, cells
from goodtables.error import Error
from goodtables.inspector import _filter_checks
from goodtables.registry import registry
from tableschema import Schema
from .rules.full_schema_constraint import (
@micimize
micimize / fab_remote_user.py
Created August 17, 2019 14:13
Full proxy control over flask app builder (and thus apache superset) authentication
from flask import Blueprint, redirect
from flask_login import current_user, logout_user
from flask_appbuilder.security.manager import AUTH_OAUTH, AUTH_REMOTE_USER
my_blueprint = Blueprint("My Blueprint", __name__)
@my_blueprint.before_app_request
def ensure_logout_correctness():
"""Ensure users are logged out when the proxy logs out
@micimize
micimize / tab_navigating_scaffold.dart
Last active April 3, 2024 19:52
Approach for tab-local navigators in flutter. Generalized from https://stackoverflow.com/a/57627826/2234013
import 'package:flutter/material.dart';
class AppScaffold extends StatefulWidget {
final List<WidgetBuilder> pages;
final List<BottomNavigationBarItem> navItems;
const AppScaffold({
Key key,
@required this.pages,
@required this.navItems,
@micimize
micimize / xonshrc.py
Last active September 14, 2019 17:22
xonshrc in progress
$XONSH_SHOW_TRACEBACK = True
import typing as t
import xonsh.jobs
from time import strftime
from prompt_toolkit.key_binding import vi_state
from xonsh.prompt.vc import dirty_working_directory
xontrib load bashisms coreutils distributed docker_tabcomplete readable-traceback
@micimize
micimize / express-google-jwt-verifier.js
Last active April 13, 2020 16:00
express middleware for verifying and decoding google jwt tokens
const { OAuth2Client } = require('google-auth-library');
function decodedTokenToUser({
// protocole concerns
iss,
azp,
aud,
at_hash,
iat,
exp,
@micimize
micimize / time_travel_trigger.sql
Last active October 3, 2019 22:37 — forked from myitcv/time_travel_trigger.sql
Trigger-based equivalent of old PostgreSQL time travel module - see http://blog.myitcv.org.uk/2014/02/25/row-level-version-control-with-postgresql.html for more details
/*
original contained the following, has since been modified
Copyright (c) 2015 Paul Jolly <paul@myitcv.org.uk)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@micimize
micimize / graphql_fragments_in_dart.dart
Last active November 10, 2019 19:54
An approach for sane graphql-style fragment inheritence in dart https://dartpad.dartlang.org/ec9df3c1df23f415621fd3da7e81209e
// base type
class Foo {
String _foo;
int _bar;
}
//fragment exposing foo
class FooFragment extends Foo {
String get foo => _foo;
set foo(String value) => _foo = value;
List<HSLColor> hslTetrad(Color color) {
final hsl = HSLColor.fromColor(color);
final baseHue = hsl.hue;
return [
hsl,
hsl.withHue((baseHue + 90) % 360),
hsl.withHue((baseHue + 180) % 360),
hsl.withHue((baseHue + 270) % 360),
];
}