This file contains 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 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 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: | |
""" |
This file contains 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
{### FILTERS ###} | |
<select id="filter1" name="filter1"> | |
<option value="" selected disabled>Filter 1</option> | |
<option value="1">One</option> | |
<option value="2">Two</option> | |
</select> | |
<select id="filter2" name="filter2"> | |
<option value="" selected disabled>Filter 2</option> | |
<option value="1">One</option> | |
<option value="2">Two</option> |
This file contains 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.db import migrations | |
from myapp.models import MyModel | |
def convert_mymodel_status(apps, schema_editor, reverse: bool | None = False): | |
""" | |
Convert "OLD STATUS" status to "NEW STATUS" | |
Or reverses these changes | |
""" | |
status = "NEW STATUS" if reverse else "OLD STATUS" | |
updated_status = "OLD STATUS" if reverse else "NEW STATUS" |
This file contains 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.db.models import Count, Min | |
unique_fields = ['field_1', 'field_2'] | |
duplicates = ( | |
MyModel.objects.values(*unique_fields) | |
.order_by() | |
.annotate(min_id=Min('id'), count_id=Count('id')) | |
.filter(count_id__gt=1) | |
) |