This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const validateDomain = (domain) => { | |
const domainRegex = /^[A-Za-z0-9-]{1,63}(\.[A-Za-z0-9-]{1,63})*\.[A-Za-z]{2,6}$/mig; | |
return domainRegex.test(domain) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Ensures only one instance runs migrations when multiple instances are spun up concurrently. | |
This prevents a deadlock scenario. | |
""" | |
from django.core.management.base import CommandError | |
from django.db import connection | |
from django.core.management.commands.migrate import Command as MigrateCommand | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from time import time | |
def binary_search(int_list: range, number: int) -> tuple[str | None, int]: | |
""" | |
Return index and number of iterations of a number in range | |
RANDOM NUMBER 940_695_391 | |
Time to complete: 0.0069141387939453125ms | |
INDEX OF RANDOM NUMBER, ('940_695_391', 31) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
# Password validation | |
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators | |
# Your password can’t be too similar to your other personal information. | |
# Your password must contain at least 10 characters. | |
# Your password can’t be a commonly used password. | |
# Your password can’t be entirely numeric. | |
# Your password must contain at least 1 symbol: ()[]{}|\`~!@#$%^&*_-+=;:'",<>./? | |
# Your password must contain at least 1 number, 0-9. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
To use this decorator, add it to the view function you want to rate limit. | |
from authentication.decorators import dynamic_rate_limit | |
@dynamic_rate_limit() | |
def login_view(request): | |
The values can be changed based on a Config model that stores values in json. | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from unittest import skipIf | |
from django.contrib.staticfiles.testing import StaticLiveServerTestCase | |
from django.conf import settings | |
from django.test.client import Client | |
# Selenium imports | |
from selenium import webdriver | |
from selenium.webdriver.common.by import By |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.myproject.mypackage.config; | |
import org.flywaydb.core.Flyway; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.boot.CommandLineRunner; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
@Configuration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on run argv | |
local basePath | |
set basePath to item 1 of argv | |
tell application "iTerm2" | |
create window with default profile | |
end tell | |
set repos to {"repo-1", "repo-2", "repo-3"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import template | |
register = template.Library() | |
@register.filter(name="truncate_with_ellipses") | |
def truncate_with_ellipses(value: str, max_length: int) -> str: | |
""" | |
Confine a string to a max length, replace last three characters with ellipses | |
""" | |
if len(value) <= max_length: | |
return value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import template | |
from django.contrib.auth import get_user_model | |
from django.contrib.auth.models import Group | |
register = template.Library() | |
User = get_user_model() | |
@register.filter(name="user_in_group") | |
def user_is_in_group(user: User, allowed_groups: str) -> bool: | |
""" |
NewerOlder