signals

python
class Product(models.Model):
    name = models.CharField(max_length=200)
    slug = models.SlugField(blank=True)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    cost = models.DecimalField(max_digits=10, decimal_places=2)
    margin = models.DecimalField(max_digits=5, decimal_places=2, blank=True)

Django model signals vs overriding save

django python models
by Priya Sharma 2 tabs
python
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.core.mail import send_mail
from .models import User, Profile

Django signals for decoupled event handling

django python signals
by Priya Sharma 2 tabs
typescript
import { AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms';

function hasActualValue(control: AbstractControl | null): boolean {
  return !!control && control.value !== null && control.value !== '';
}

Cross-Field Password-Confirmation Validator for Angular Reactive Forms

angular reactive-forms validators
by codesnips 3 tabs
go
package worker

import (
	"context"
	"errors"
	"log"

Fan-Out Worker Pool With Context Cancellation and Graceful Shutdown in Go

go concurrency goroutines
by codesnips 2 tabs
erb
{% load cache %}
<section class="dashboard">
  <h1>{{ team.name }} — Overview</h1>

  {% cache 3600 team_order_stats team.id stats_version %}
    <div class="stat-grid">

Cache an Expensive Dashboard Fragment with Django's Template Cache Tag and Signal-Based Invalidation

django caching template-cache
by codesnips 3 tabs
javascript
function createReadiness() {
  let ready = true;

  function markUnready() {
    ready = false;
  }

Graceful HTTP Server Shutdown on SIGTERM With In-Flight Request Draining in Node.js

nodejs http graceful-shutdown
by codesnips 3 tabs
typescript
import { Injectable, computed, signal } from '@angular/core';

@Injectable({ providedIn: 'root' })
export class LoadingService {
  private readonly activeRequests = signal(0);

Global Loading Spinner via In-Flight Request Tracking in an Angular HttpInterceptor

angular http-interceptor rxjs
by codesnips 4 tabs
python
from django.conf import settings
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models, transaction

from .middleware import get_current_user

Auditing Django Model Field Changes in an Overridden save() Method

django audit-log orm
by codesnips 3 tabs
go
package worker

import "context"

func (p *Pool) Submit(job Job) error {
	// Reject fast if draining, otherwise enqueue with backpressure.

Graceful Drain of In-Flight Jobs Before Worker Shutdown in Go

go graceful-shutdown concurrency
by codesnips 3 tabs
javascript
const SHUTDOWN_TIMEOUT_MS = 10_000;

function registerFatalHandlers({ logger, onFatal, exitCode = 1 }) {
  let shuttingDown = false;

  async function handleFatal(kind, error) {

Graceful Node.js Shutdown on uncaughtException and unhandledRejection

node reliability graceful-shutdown
by codesnips 3 tabs
python
from django.db import models
from django.utils.text import slugify


class Article(models.Model):
    title = models.CharField(max_length=200)

Auto-Generate Unique Slugs in Django with a pre_save Signal and Model Method

django signals slugs
by codesnips 3 tabs
typescript
import { Injectable, signal, computed } from '@angular/core';

export interface CurrentUser {
  id: string;
  email: string;
  roles: string[];

Guarding a Lazy-Loaded Angular Admin Route with a Functional CanActivate Role Check

angular routing lazy-loading
by codesnips 3 tabs