Skip to content

Instantly share code, notes, and snippets.

View adhadse's full-sized avatar
🐧

Anurag Dhadse adhadse

🐧
View GitHub Profile
@adhadse
adhadse / index.html
Last active November 27, 2020 13:57
HTML syntax to store product ID and Action
<!- ALong with other HTML -->
<button type="button" class="btn btn-light btn-block border mt-2 update-wishlist" data-action="add" data-product="{{ product.productID }}">
<span class="text"> Add to Wishlist</span>
</button>
@adhadse
adhadse / index.js
Last active November 27, 2020 13:58
using javascript to search the element
window.addEventListener('load',function () {
console.log('Loaded')
let wislistBtns = document.querySelectorAll('.update-wishlist')
if (wislistBtns) {
for (let i = 0; i < wislistBtns.length; i++) {
wislistBtns[i].addEventListener('click', function () {
const productID = this.dataset.product
const action = this.dataset.action
console.log('productID:', productID, 'Action:', action)
if (user === 'AnonymousUser') {
@adhadse
adhadse / index.js
Last active November 27, 2020 14:00
updateUserWihslist
function updateUserWishlist(productID,action){
console.log('user:',user,' is Authenticated, sending data')
let url= '/api/update_wishlist/'
fetch(url,{
method:'PUT',
headers:{
'Content-Type':'application/json',
'X-CSRFToken':csrftoken,
},
body:JSON.stringify({'productID':productID, 'action':action})
# Application definition
INSTALLED_APPS = [
'rest_framework',
'serverapi.apps.ServerapiConfig',
'otherapp',
'otherapp2',
]
@adhadse
adhadse / urls.py
Last active December 3, 2020 15:40
# serverapi\urls.py
from django.urls import path
from serverapi import views
appname = 'serverapi'
urlpatterns = [
path('update_wishlist/', views.updateWishlist, name='updateWishlist'),
]
# yourproject\urls.py
# add your other necessary imports
urlspatterns = [
re_path('^api/', include(('serverapi.urls', 'serverapi'), namespace='api')),
]
@adhadse
adhadse / views,py
Last active November 27, 2020 15:14
# serverapi\view.py
from rest_framework.decorators import api_view
from django.http import JsonResponse
@api_view(['PUT'])
def updateWishlist(request):
data = json.loads(request.body)
productID = data['productID']
action = data['action']
print('ProductID:', productID)
function updateNavbar(data){
document.getElementById('wishlist').innerHTML = 'Wishlist<span class="badge badge-danger" style="vertical-align: top;"><h7>' + data['wishlistItemQuantity'] + '</h7></span>'
}
let user = '{{ request.user }}'
function getToken(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
def plot_precision_recall_vs_threshold(precisions, recalls, thresholds, metric_name=None, metric_perc=None):
plt.figure(figsize=(15, 10))
plt.plot(thresholds, precisions[:-1], 'b--', label='Precision')
plt.plot(thresholds, recalls[:-1], 'g-', label='Recall')
plt.xlabel('Threshold', fontsize=15)
plt.axis([-50000, 50000, 0, 1])
plt.legend(loc='best', fontsize=16)
if metric_name=='precision':
metric = precisions