decorators

ruby
# Gemfile
gem 'draper'

# app/decorators/user_decorator.rb
class UserDecorator < Draper::Decorator
  delegate_all

Decorator pattern with Draper for view logic

ruby rails draper
by Sarah Mitchell 2 tabs
python
import time
import threading
from collections import deque, defaultdict


class SlidingWindowLimiter:

Sliding-Window Rate Limiting in Flask With a Custom Decorator and In-Memory Buckets

flask rate-limiting decorators
by codesnips 3 tabs
python
import abc
from typing import IO


class Exporter(abc.ABC):
    name: str = ""

Plugin Registry with Class Decorators and setuptools Entry-Point Discovery

python plugins decorators
by codesnips 4 tabs
python
from dataclasses import dataclass, field
from datetime import datetime, timezone
from decimal import Decimal


def _now():

Synchronous Domain Event Bus with a Registry-Based Publisher in Python

domain-events event-bus pubsub
by codesnips 3 tabs
python
import errno
import fcntl
import os
import time

File-Based Locking to Prevent Concurrent Cron Job Runs in Python

locking concurrency fcntl
by codesnips 3 tabs
python
import functools
import threading


def debounce(wait):
    def decorator(func):

Debounce Repeated Function Calls With a Thread-Safe Python Decorator

python decorators debounce
by codesnips 2 tabs
ruby
class ReportsController < ApplicationController
  def monthly_sales
    year = params.fetch(:year, Date.current.year).to_i
    rows = Order.monthly_sales(year: year)
    @report = MonthlySalesReport.new(rows, year: year)

Aggregate Monthly Sales Reports in Rails with group_by SQL and a Presenter

rails postgres reporting
by codesnips 3 tabs
python
from functools import wraps
from django.http import JsonResponse
from django.core.cache import cache


def ajax_required(view_func):

Django custom decorators for view logic

django python decorators
by Priya Sharma 1 tab
python
import functools
import threading
import time
from collections import OrderedDict

Custom TTL + LRU Cache Decorator for Expensive Python Computations

python caching lru
by codesnips 2 tabs