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 typing import Type, List | |
from django.db import models, connection | |
class OrdererByID: | |
"""Helper class to update rows in table according to order of list of IDs provided.""" | |
def __init__(self, *, model: Type[models.Model], field_name: str) -> None: | |
self.reorder_query = f""" |
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
CREATE TYPE MOOD AS ENUM ('sad', 'ok', 'happy'); | |
CREATE TABLE person_with_type ( | |
name TEXT, | |
current_mood MOOD DEFAULT 'ok' | |
); | |
INSERT INTO person_with_type (name, current_mood) | |
SELECT | |
name, |
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, Max | |
from django.db.models.functions import Coalesce | |
def chunk_fetch(queryset, chunk_size=100): | |
""" | |
:type chunk_size: int | |
:type queryset: django.db.models.QuerySet | |
""" | |
aggregation = queryset.aggregate( | |
min_id=Coalesce(Min('pk'), 0), |
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 celery import Task | |
from django.conf import settings | |
from django.core.cache import caches | |
from celery.utils.log import get_task_logger | |
logger = get_task_logger(__name__) | |
# noinspection PyAbstractClass | |
class TaskWithLock(Task): | |
""" |
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
#include <AutoItConstants.au3> | |
HotKeySet("{PAUSE}", "LoopFlagToggle") | |
$loopflag = False | |
$random = False | |
$only_clicks = False | |
$dx = 50 | |
$dy = 50 |
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
'use strict'; | |
var _ = require('lodash'); | |
var Attribute = require('./attribute.model.js'); | |
// Get list of mappings | |
exports.index = function (req, res) { | |
Attribute.find(req.query, function (err, mappings) { | |
if (err) { | |
return handleError(res, err); |