Skip to content

Instantly share code, notes, and snippets.

View harunurkst's full-sized avatar

Harun Ur Rashid harunurkst

View GitHub Profile
@harunurkst
harunurkst / aggregate_sum.py
Created July 24, 2023 23:47
Django Aggregate SUM example
deposit_sum = Sum('amount', filter=Q(transaction_type='deposit'))
withdraw_sum = Sum('amount', filter=Q(transaction_type='withdraw'))
deposit = Savings.objects.filter(branch=branch).aggregate(
total_deposit= deposit_sum - withdraw_sum
)['total_deposit']
with open(str(BASE_DIR) + '/oidc.key', 'rb') as f:
OIDC_RSA_PRIVATE_KEY = f.read().decode()
#!/bin/bash
# Initialize credential veriable
dbname=teamshape
dbuser=admin
userpass=admin
# install python3.8
echo "Installing python3.8"
sudo add-apt-repository ppa:deadsnakes/ppa
$.ajax({
url: apiUrl,
method: 'POST',
contentType: "application/json",
dataType: 'json',
data: JSON.stringify(orderData),
headers: {
'X-CSRFToken': csrftoken,
'Accept': 'application/json',
'Content-Type': 'application/json'
@harunurkst
harunurkst / object_count_per_month.py
Last active November 10, 2020 04:47
Count number of object created or total number of amount per month in Django
class FundRaisePerMonth(APIView):
def get(self, request):
year = datetime.date.today().year
# Filter data as monthly(number serial) [{'month_serial': views_count} like [{'1': 50, '2': 55}]
queryset = CustomUser.objects.filter(date_joined__year=year)
search = queryset.annotate(month=ExtractMonth('date_joined'),).order_by('month').values('month')\
.annotate(total=Sum('amount')).values('month', 'total')
# convert int month to str month, 1 to January
data = []
@harunurkst
harunurkst / datatable_with_django.js
Created February 9, 2020 06:10
Use JQuery datatable with Django Rest Framework
$(document).ready(function(){
$('#search-data').dataTable( {
destroy: true, // destroy previous datatable to remove error.
"ajax": url,
"columns": [
{"data":"latitude"},
{"data":"longitude"},
{"data":"data__product_data__Name"},
{"data":"id__count"},
]
@harunurkst
harunurkst / clean_database_tables.py
Last active November 10, 2020 04:48
Drop all tables of postgresql with python code
from django.db import connections, OperationalError
# Drop all tables from a given database
"""
python manage.py runscript clean_database_tables
"""
def run():
@harunurkst
harunurkst / commands.py
Last active August 18, 2019 11:42
important commands
# run bash in docker image
# docker run -it <image-name> bash
# if entrypoint defined
docker run -it --entrypoint bash jifcastback_djangoapp
# create superuser in docer container django app
sudo docker-compose run --entrypoint="python manage.py createsuperuser" djangoapp
{% extends 'base.html' %}
{% block content %}
<div class="container">
<div class="dashboard-block">
<h2 class="dashboard-info-title">Profile Info</h2>
<form method="POST" action="{% url 'userprofile:create-profile' %}" enctype="multipart/form-data">{% csrf_token %}
{% for field in form %}
def djangoview(request, language1, language2):
async def main(language1, language2):
loop = asyncio.get_event_loop()
r = sr.Recognizer()
with sr.AudioFile(path.join(os.getcwd(), "audio.wav")) as source:
audio = r.record(source)
def reco_ibm(lang):
return(r.recognize_ibm(audio, key, secret language=lang, show_all=True))
future1 = loop.run_in_executor(None, reco_ibm, str(language1))
future2 = loop.run_in_executor(None, reco_ibm, str(language2))