01-JS Fundamentals | Javascript introduction

JS introduction and Variable declaration and scope

๐Ÿ“… Jan 6, 2024

Introduction to JS

What is JavaScript?

  • JavaScript is a dynamic, weakly typed programming language which is compiled at runtime.
  • It can be executed as part of a webpage in a browser or directly on any machine (โ€œhost environmentโ€).
  • JavaScript was created to make webpages more dynamic (e.g. change content on a page directly from inside the browser).
Read More โ†’

Cookies and Web Storage

Local Storage, Session Storage And Cookies

๐Ÿ“… Jan 2, 2024

Cookies

  • Cookies are small strings(max size 4KB) of data that are stored directly in the browser.
  • They are a part of the HTTP protocol, defined by the RFC 6265 specification
  • Sent to server on ecah request
  • Cookies are usually set by a web-server using the response Set-Cookie HTTP-header.
  • One cookie must not exceed 4KB, 20+ cookies per site(depends on the browser)
Read More โ†’

Node Js Installation

About Nodejs and Installation

๐Ÿ“… Jan 2, 2024

Node Js

Node.js lets you run JavaScript outside the browser, primarily for building back-end services, tools, or full-stack applications.

Node Installation

Check version

node -v

npm -v

nvm -v

Option 1: Install from Official Website

  • Go to: https://nodejs.org
  • Youโ€™ll see two options:
    • LTS (Long-Term Support) โ€“ Stable, recommended for most users
    • Current โ€“ Latest features, but may be less stable.
  • Download and install the LTS version.

This installs both Node.js and npm (Node Package Manager).

Read More โ†’

04-Django Adv

Throttling - API rate limiting

๐Ÿ“… Aug 9, 2023

Throttling

API rate limiting is a technique used to control the number of requests a user or client can make to an API within a specific time frame. In Django, you can implement rate limiting using third-party libraries like Django REST Framework’s (DRF) throttling or by integrating specialized libraries like django-ratelimit.

4.1 Using Django REST Framework (DRF) Throttling

DRF provides built-in throttling classes to enforce rate limits.

Period should be one of: (’s’, ‘sec’, ’m’, ‘min’, ‘h’, ‘hour’, ’d’, ‘day’)

Read More โ†’

03-Django Adv

Logging Works in Django

๐Ÿ“… Aug 8, 2023

Logger

Print statement generally does not work in production so, to get message we use logger

What is Logging?

How Logging Works in Django

  • Django comes with Python's built-in logging module to leverage system logging.
    1. Loggers
    2. Handlers
    3. Filters
    4. Formatters

Loggers

  • Loggers are basically the entry point of the logging system.
  • If the log-level is same or exceeds the log-level of the logger, the message is sent to the handler for further processing.
DEBUG:		     10 --> Low-level system information
INFO:		     20 --> General system information
WARNING:	     30 --> Minor problems related information
ERROR/EXCEPTION: 40 --> Major problems related information
CRITICAL:	     50 --> Critical problems related information
dblogger.debug("Test Debug")

dblogger.info("Test Info")

dblogger.warning("Test Warning")
dblogger.warn("Test Warn")  # Depricated

dblogger.error("Test Error")
dblogger.exception("Test Exception")

dblogger.critical("Test Critical")

Handlers

Handlers basically determine what happens to each message in a logger eg: write to a file or console.

Read More โ†’

03-Django Adv

๐—–๐—ฟ๐—ผ๐˜€๐˜€-๐—ข๐—ฟ๐—ถ๐—ด๐—ถ๐—ป ๐—ฅ๐—ฒ๐˜€๐—ผ๐˜‚๐—ฟ๐—ฐ๐—ฒ ๐—ฆ๐—ต๐—ฎ๐—ฟ๐—ถ๐—ป๐—ด (๐—–๐—ข๐—ฅ๐—ฆ)

๐Ÿ“… Aug 7, 2023

๐—–๐—ฟ๐—ผ๐˜€๐˜€-๐—ข๐—ฟ๐—ถ๐—ด๐—ถ๐—ป ๐—ฅ๐—ฒ๐˜€๐—ผ๐˜‚๐—ฟ๐—ฐ๐—ฒ ๐—ฆ๐—ต๐—ฎ๐—ฟ๐—ถ๐—ป๐—ด (๐—–๐—ข๐—ฅ๐—ฆ)

CORS is a security mechanism enforced by web browsers to restrict cross-origin HTTP requests.

CORS is a mechanism implemented by browsers that block websites to request data from some other URL. When a browser makes a request, it adds an origin header to the request message. If it goes to the server of the exact origin, it is allowed by the browser; if it does not, the browser blocks it. gets error like Cross-Origin Request Blocked

Read More โ†’

01-Django Adv

Django postgres full text search

๐Ÿ“… Aug 6, 2023
  • Unlike relational databases, full-text search is not standardized.
  • There are several open-source options like ElasticSearch, Solr, and Xapian.
  • For general uses
    • We can stick with the full-text search capabilities that many relational (like Postgres, MySQL, SQLite)
    • And non-relational databases (like MongoDB and CouchDB) offer.
  • In Django you’ll typically start by performing search queries with contains or icontains for exact matches.
  • The Q object can be used as well to add AND (&) or OR (|) logical operators.
  • Limitations
    • Only exact match is shown –> similar words excluded
    • Stop word(article) all has same weight
    • complex lookups not possible
from django.db.models import Q

ProductDetail.objects.filter(Q(name__icontains=query))

Quote.objects.filter(Q(name__icontains=query) | Q(quote__icontains=query))
  • Eg:
    • query = pony
    • then ponies != pony
  • To use the search lookup, django.contrib.postgres must be in your INSTALLED_APPS.
  • Used for Single Field Search
  • Advantage
    • It takes similar words into account
      • ponies, pony
INSTALLED_APPS += ['django.contrib.postgres']

ProductDetail.objects.filter(name__search=query)

SearchVector

  • To search against multiple fields and on related models, you can use the SearchVector
Entry.objects.annotate(search=SearchVector('body_text') + SearchVector('blog__tagline')).filter(search=query)

Quote.objects.annotate(search=SearchVector("name", "quote")).filter(search=query)

SearchQuery

SearchQuery translates the terms the user provides into a search query object that the database compares to a search vector. By default, all the words the user provides are passed through the stemming algorithms, and then it looks for matches for all of the resulting terms.

Read More โ†’