python

python
from haystack import indexes
from blog.models import Post


class PostIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)

Django haystack for advanced search

django python search
by Priya Sharma 2 tabs
python
from sklearn.decomposition import PCA
from sklearn.manifold import TSNE
from sklearn.preprocessing import StandardScaler

X_scaled = StandardScaler().fit_transform(X)

PCA and t-SNE for dimensionality reduction and inspection

pca tsne dimensionality-reduction
by Dr. Elena Vasquez 1 tab
python
import great_expectations as gx

context = gx.get_context()
data_source = context.data_sources.add_pandas(name='training_data')
asset = data_source.add_dataframe_asset(name='churn_asset')
batch_definition = asset.add_batch_definition_whole_dataframe('full_dataframe')

Great Expectations checks for dataset health before retraining

great-expectations data-quality mlops
by Dr. Elena Vasquez 1 tab
python
import time
import requests
from bs4 import BeautifulSoup

session = requests.Session()
session.headers.update({'User-Agent': 'research-bot/1.0'})

Web scraping pipelines with requests and BeautifulSoup

web-scraping beautifulsoup requests
by Dr. Elena Vasquez 1 tab
python
import enum
import datetime as dt

from sqlalchemy import Column, Integer, String, BigInteger, Enum, DateTime
from sqlalchemy.orm import declarative_base

Streaming FastAPI File Uploads with a Background Validation Task

fastapi uploads background-tasks
by codesnips 3 tabs
python
from sklearn.ensemble import RandomForestClassifier, HistGradientBoostingClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import roc_auc_score
from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer

Baseline classifiers in scikit-learn for fast benchmark setting

scikit-learn classification baselines
by Dr. Elena Vasquez 1 tab
python
from django.conf import settings
from django.db import models
from django.utils import timezone


class InvoiceQuerySet(models.QuerySet):

Scope a Django DetailView to the Request User with get_queryset

django authorization class-based-views
by codesnips 3 tabs
sql
CREATE TABLE events (
    id          bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    source      text        NOT NULL,
    external_id text        NOT NULL,
    payload     jsonb       NOT NULL,
    occurred_at timestamptz NOT NULL,

Batched writes with COPY (conceptual)

postgres performance sql
by codesnips 3 tabs
python
import torch

device = 'cuda' if torch.cuda.is_available() else 'cpu'
features = torch.tensor([[1.0, 2.0], [3.0, 4.0]], requires_grad=True, device=device)
weights = torch.tensor([[0.2], [0.8]], requires_grad=True, device=device)

PyTorch tensor basics and automatic differentiation

pytorch tensors autograd
by Dr. Elena Vasquez 1 tab
python
import factory
from factory.django import DjangoModelFactory
from factory import Faker, SubFactory, post_generation
from blog.models import Post, Comment, Tag
from django.contrib.auth import get_user_model

Django test fixtures with factory_boy

django python testing
by Priya Sharma 1 tab
python
from django.contrib.auth import views as auth_views
from django.urls import path

app_name = 'accounts'

urlpatterns = [

Django password reset flow with email

django python authentication
by Priya Sharma 2 tabs
python
import time
from collections import namedtuple

from sqlalchemy import text

CheckResult = namedtuple("CheckResult", ["name", "healthy", "latency_ms", "detail"])

Flask Health-Check Blueprint Reporting Database and Redis Status as JSON

flask health-check observability
by codesnips 3 tabs