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
| image: atlassian/default-image:2 | |
| pipelines: | |
| branches: | |
| master: | |
| - step: | |
| name: Deploy to Production | |
| deployment: production | |
| script: |
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
| #!/usr/bin/python | |
| # -*- coding: utf-8 -*- | |
| # flask related modules | |
| from flask import Flask, Response | |
| from flask_basicauth import BasicAuth | |
| from flask_admin import Admin | |
| from flask_admin.contrib import sqla | |
| from werkzeug.exceptions import HTTPException | |
| # database set up |
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
| ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key | |
| # Don't add passphrase | |
| openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub | |
| cat jwtRS256.key | |
| cat jwtRS256.key.pub |
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 requests #dependency | |
| import json | |
| url = "<your url>" #webhook url, from here: https://i.imgur.com/aT3AThK.png | |
| data = {} | |
| #for all params, see https://discordapp.com/developers/docs/resources/webhook#execute-webhook | |
| data["content"] = "message content" | |
| data["username"] = "custom username" |
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) | |
| ) |
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
| # in DRF DestroyModelMixin delete row. Using Same DELETE method I can soft delete object. | |
| # ex: URL - DELETE https://<hostnam>/api/v1/books/1/ | |
| from rest_framework import mixins, permissions, viewsets | |
| from rest_framework.response import Response | |
| from rest_framework import status | |
| class SlSoftDeleteMixin(mixins.DestroyModelMixin): | |
| """ As we are deleting soft""" |
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
| label | |
| input#test-checkbox type="checkbox" | |
| |Test checkbox | |
| table#test-table | |
| javascript: | |
| $(document).ready(function() { | |
| var table = $("#test-table").dataTable( { | |
| "ajaxSource": '#{test_datatable_path}', |
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
| # How to display only interesting fields for a Django Rest Framework API | |
| # /?fields=field1,field2,field3 | |
| from rest_framework import serializers, pagination | |
| class DynamicFieldsModelSerializer(serializers.ModelSerializer): | |
| """ | |
| A ModelSerializer that takes an additional `fields` argument that | |
| controls which fields should be displayed. |
NewerOlder