Skip to content

Instantly share code, notes, and snippets.

@a4amaan
a4amaan / DRF-dynamic-fields.py
Created November 26, 2019 09:55 — forked from Kmaschta/DRF-dynamic-fields.py
Django Rest Framework - Dynamic Fields
# 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.
@a4amaan
a4amaan / test.html.slim
Created February 7, 2020 15:35 — forked from kossoff/test.html.slim
Custom parameters for jQuery Datatables with server-side processing
label
input#test-checkbox type="checkbox"
|Test checkbox
table#test-table
javascript:
$(document).ready(function() {
var table = $("#test-table").dataTable( {
"ajaxSource": '#{test_datatable_path}',
@a4amaan
a4amaan / DRF Soft delete mixin
Created April 8, 2020 18:13 — forked from jadhavmanoj/DRF Soft delete mixin
Django Rest Framework (DRF) Soft delete Mixin.
# 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"""
@a4amaan
a4amaan / remove_duplicates.py
Created April 13, 2020 16:57 — forked from victorono/remove_duplicates.py
Django - remove duplicate objects where there is more than one field to compare
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)
)
@a4amaan
a4amaan / webhook.py
Created September 11, 2020 11:08 — forked from Bilka2/webhook.py
Simple discord webhook with python
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"
@a4amaan
a4amaan / jwtRS256.sh
Created February 12, 2021 20:32 — forked from ygotthilf/jwtRS256.sh
How to generate JWT RS256 key
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
@a4amaan
a4amaan / flask-admin-with-flask-basicauth-login-example.py
Created March 19, 2021 20:12 — forked from shisaq/flask-admin-with-flask-basicauth-login-example.py
flask-admin with flask-basicauth login example(Flask-BasicAuth简单登录Flask-admin后台)
#!/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
@a4amaan
a4amaan / bitbucket-pipelines.yml
Created March 23, 2021 10:51 — forked from cabrerahector/bitbucket-pipelines.yml
Bitbucket Pipelines - Deploying to Server with atlassian/ftp-deploy
image: atlassian/default-image:2
pipelines:
branches:
master:
- step:
name: Deploy to Production
deployment: production
script:
<template>
<q-page
class="window-height window-width row justify-center items-center"
style="background: linear-gradient(#8274C5, #5A4A9F);"
>
<div class="column q-pa-lg">
<div class="row">
<q-card square class="shadow-24" style="width:300px;height:485px;">
<q-card-section class="bg-deep-purple-7">
<h4 class="text-h5 text-white q-my-md">Company &amp; Co</h4>
@a4amaan
a4amaan / mongodb-objectid.js
Created April 12, 2021 20:29 — forked from chrisveness/mongodb-objectid.js
Generates a MongoDB-style ObjectId in Node.js
/**
* Generates a MongoDB-style ObjectId in Node.js. Uses nanosecond timestamp in place of counter;
* should be impossible for same process to generate multiple objectId in same nanosecond? (clock
* drift can result in an *extremely* remote possibility of id conflicts).
*
* @returns {string} Id in same format as MongoDB ObjectId.
*/
function objectId() {
const os = require('os');
const crypto = require('crypto');