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 channels.auth import AuthMiddlewareStack | |
| from channels.routing import ProtocolTypeRouter, URLRouter | |
| import apps.solicitudes.routing | |
| application = ProtocolTypeRouter({ | |
| "websocket": AuthMiddlewareStack( | |
| URLRouter( | |
| apps.solicitudes.routing.websocket_urlpatterns | |
| ) | |
| ), |
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
| go to | |
| cd /etc/postgresql/10/main | |
| rm postgresql.conf | |
| touch postgresql.conf | |
| nano postgresql.conf | |
| copy and paste below code, get fun :) |
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
| testdb=> SELECT name,setting,unit FROM pg_settings; | |
| name | setting | unit | |
| ---------------------------------+---------------------------------------------+------ | |
| allow_system_table_mods | off | | |
| application_name | psql | | |
| archive_command | /etc/rds/dbbin/pgscripts/rds_wal_archive %p | | |
| archive_mode | on | | |
| archive_timeout | 300 | s | |
| array_nulls | on | | |
| authentication_timeout | 60 | s |
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
| var express = require('express') | |
| var app = express() | |
| var AWS = require('aws-sdk'); | |
| var bodyParser = require('body-parser'); | |
| var fs = require('fs'); | |
| var zlib = require('zlib'); // gzip compression | |
| var multiparty = require('connect-multiparty'), | |
| multipartyMiddleware = multiparty(); |
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
| npm install nodemon | |
| nodemon --exec "sls offline start" -e "extensions,to,watch,for,example,js,elm,hs,py" | |
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
| @action(detail=False, methods=['get']) | |
| def action_view(self, request): | |
| queryset = self.model.objects.all() | |
| page = self.paginate_queryset(queryset) | |
| if page is not None: | |
| serializer = self.get_serializer(page, many=True) | |
| return self.get_paginated_response(serializer.data) | |
| serializer = self.get_serializer(queryset, many=True) | |
| return Response(serializer.data) |
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.db.models import Transform | |
| class Trigram(Transform): | |
| bilateral = True | |
| lookup_name = 'trigram' | |
| def as_postgresql(self, compiler, connection): | |
| lhs, params = compiler.compile(self.lhs) | |
| return "TRIAGRAM(%s)" % lhs, params |
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
| class PaginatorMixin(object): | |
| min_limit = 1 | |
| max_limit = 10 | |
| def paginate(self, object_list, page=1, limit=10, **kwargs): | |
| try: | |
| page = int(page) | |
| if page < 1: | |
| page = 1 | |
| except (TypeError, ValueError): |
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
| class CustomAuthenticationBackend: | |
| def authenticate(self, request, email_or_phone=None, password=None): | |
| try: | |
| user = User.objects.get( | |
| Q(email=email_or_phone) | Q(phone=email_or_phone) | |
| ) | |
| pwd_valid = user.check_password(password) | |
| if pwd_valid: | |
| return user |
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.db.models import Count, Max | |
| unique_fields = ['field_1', 'field_2'] | |
| duplicates = ( | |
| MyModel.objects.values(*unique_fields) | |
| .order_by() | |
| .annotate(max_id=Max('id'), count_id=Count('id')) | |
| .filter(count_id__gt=1) | |
| ) |