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
class TrackAttrsMixin: | |
""" | |
Keep eye on TRACK_ATTRS, so we can know if they changed before doing any actions | |
TRACK_ATTRS should not be empty | |
""" | |
TRACK_ATTRS: Iterable[str] = () | |
def __init__(self, *args, **kwargs): | |
if not self.TRACK_ATTRS: | |
raise ValueError("TRACK_ATTRS should contain at least one 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
# show only file names | |
git diff --name-only SHA HEAD~1 > diff.txt | |
# delete old branches | |
git branch -a > branches.txt # dump all branches to file | |
&& sed -i '' 's/\/remote\/origin\///g' branches.txt # replace unneeded '/remote/origin/' prefix | |
&& nano branches.txt # manually delete branches that need to be keeped | |
&& cat branches.txt | xargs -I {} git push origin :{} # delete unneeded branches | |
# show added/deleted lines count |
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
<template> | |
<span>{{ tweeningValue }}</span> | |
</template> | |
<script> | |
import TWEEN from 'tween.js'; | |
export default { | |
name: 'animated-integer', | |
props: { |
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 rest_framework import viewsets | |
from rest_framework.request import Request | |
from rest_framework.response import Response | |
class UserViewSet(viewsets.ModelViewSet): | |
def retrieve(self, request: Request, *args, **kwargs): | |
""" | |
If provided 'pk' is "me" then return the current user. | |
""" | |
if kwargs.get('pk') == 'me': |
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 sentry:onbuild |
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
class AuthMiddlewareAwareHttpRequest(django.http.HttpRequest): | |
if 'django.contrib.auth' in django.conf.settings.MIDDLEWARE: | |
user: django.contrib.auth.models.AbstractUser | |
def myview(request: AuthMiddlewareAwareHttpRequest): | |
pass |
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
class BriefListMixin: | |
""" | |
Sometimes front-end needs brief list of models | |
Need to override brief_fields mapping like | |
{'frontend_name': 'model_field'} | |
""" | |
brief_fields = {} | |
@decorators.list_route(methods=['GET', ], url_path='brief') |
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
import uuid | |
import psycopg2 | |
from django.conf import settings | |
from django.db.backends import utils | |
from django.db.backends.postgresql.base import \ | |
DatabaseWrapper as PostgresqlDatabaseWrapper | |
from django.db.backends.postgresql.base import * | |
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
// Not so usefull | |
// After failed request do another request in new window | |
var url = 'endpoint-url-of-your-ajax-request-without-query-params' | |
$.get( | |
url + '?param1=false' | |
).fail(function (jqXHR) { | |
// open debugger in new window | |
var endpointUrl = url, | |
debuggerWindow = window.open('', 'werkzeug debugger'); | |
debuggerWindow.document.open(); |
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
"""Collect profiling statistic into graphite""" | |
import socket | |
import time | |
CARBON_SERVER = '127.0.0.1' | |
CARBON_PORT = 2003 | |
class Stats(object): |
NewerOlder