class Post < ApplicationRecord
belongs_to :author, class_name: 'User'
has_many :comments, dependent: :destroy
scope :published, -> { where.not(published_at: nil).where('published_at <= ?', Time.current) }
scope :draft, -> { where(published_at: nil) }
pub struct Server {
host: String,
port: u16,
workers: usize,
}
import { ReactNode } from 'react'
interface CardProps {
children: ReactNode
className?: string
}
class User < ApplicationRecord
has_many :posts, foreign_key: :author_id, dependent: :destroy
before_validation :normalize_email
before_create :generate_auth_token
after_create :send_welcome_email
use once_cell::sync::Lazy;
use regex::Regex;
static EMAIL_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^[^ @]+@[^ @]+.[^ @]+$").unwrap()
});
import SwiftUI
struct PostDetailView: View {
@StateObject private var viewModel: PostDetailViewModel
init(postId: Int) {
import { useState, useEffect } from 'react'
export function useDebounce<T>(value: T, delay: number = 500): T {
const [debouncedValue, setDebouncedValue] = useState<T>(value)
useEffect(() => {
class CreatePostService
def initialize(author:, params:)
@author = author
@params = params
end
class SnipPolicyScope
def initialize(member, relation = Snip.all)
@member = member
@relation = relation
end
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct UserId(u32);
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct PostId(u32);
import React, { createContext, useContext, useState, ReactNode } from 'react'
interface TabsContextType {
activeTab: string
setActiveTab: (tab: string) => void
}
from django.db import models
from django.utils import timezone
class SoftDeleteManager(models.Manager):
def get_queryset(self):