Skip to content

Instantly share code, notes, and snippets.

View custom_metrics.py
@metric("median")
def median_metric(data: DataFrame) -> Optional[Union[float, int]]:
"""Computes the median of a data series.
Args:
data: Data series.
Returns:
DataFrame median value or None if DataFrame is empty.
"""
series = df_to_series(data)
if len(series) == 0:
@alongubkin
alongubkin / log_predictions.js
Created Oct 14, 2021
Log predictions to Aporia from Node.js
View log_predictions.js
import fetch from "node-fetch";
const APORIA_TOKEN = "<TOKEN>";
async function logPredictions(data) {
const query = `
mutation LogPredict(
$modelId: String!,
$modelVersion: String!,
$environment: String!,
@alongubkin
alongubkin / get_models_and_versions
Created Sep 6, 2021
Get models & versions through GraphQL API
View get_models_and_versions
curl --request POST \
--url <APORIA_HOST>/v1/tenant-hasura/v1/graphql \
--header 'Authorization: Bearer <TOKEN>' \
--header 'Content-Type: application/json' \
--data \
'{
"query": "query { models { id name versions { id name } } }",
"variables": {}
}'
@alongubkin
alongubkin / Dockerfile
Last active Jun 7, 2021
Dockerfile + Makefile + GitHub Action
View Dockerfile
FROM python:3.8-slim
WORKDIR /my_model
STOPSIGNAL SIGINT
ENV LISTEN_PORT 80
# System dependencies
RUN apt update && apt install -y libgomp1
RUN pip3 install poetry
@alongubkin
alongubkin / iris.csv
Created Jun 7, 2021
LightGBM example
View iris.csv
sepal.length sepal.width petal.length petal.width variety
5.1 3.5 1.4 .2 Setosa
4.9 3 1.4 .2 Setosa
4.7 3.2 1.3 .2 Setosa
4.6 3.1 1.5 .2 Setosa
5 3.6 1.4 .2 Setosa
5.4 3.9 1.7 .4 Setosa
4.6 3.4 1.4 .3 Setosa
5 3.4 1.5 .2 Setosa
4.4 2.9 1.4 .2 Setosa
@alongubkin
alongubkin / TraefikRoute.ts
Last active Jun 30, 2022
Create Traefik IngressRoute with strip prefix & add trailing slash using Pulumi
View TraefikRoute.ts
import * as pulumi from '@pulumi/pulumi';
import * as k8s from '@pulumi/kubernetes';
export interface TraefikRouteArgs {
namespace: pulumi.Input<string>;
prefix: pulumi.Input<string>;
service: pulumi.Input<k8s.core.v1.Service>;
}
export default class TraefikRoute extends pulumi.ComponentResource {
@alongubkin
alongubkin / S3ServiceAccount.ts
Last active Oct 26, 2022
Create Kubernetes ServiceAccount with access to S3 using Pulumi
View S3ServiceAccount.ts
import * as pulumi from '@pulumi/pulumi';
import * as aws from '@pulumi/aws';
import * as k8s from '@pulumi/kubernetes';
export interface S3ServiceAccountArgs {
oidcProvider: aws.iam.OpenIdConnectProvider;
namespace: pulumi.Input<string>;
readOnly: pulumi.Input<boolean>;
}
View untitled0.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.