Skip to content

Instantly share code, notes, and snippets.

View Vibhu-Agarwal's full-sized avatar
🐍
Having fun with projies

Vibhu Agarwal Vibhu-Agarwal

🐍
Having fun with projies
View GitHub Profile
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
def inorder(root):
if root.left is not None:
inorder(root.left)
@Vibhu-Agarwal
Vibhu-Agarwal / RESTful APIs.md
Last active June 3, 2021 16:15
Lightning talk idea
@Vibhu-Agarwal
Vibhu-Agarwal / Problem.md
Last active April 26, 2020 12:55
API Design for particular use-case

I've to design APIs, with MongoDB being used as storage.
Will be using Node/ExpressJS for now.

So ... here's my use case.
There would be a lot of attributes/fields in each MongoDB document (more than 20)
But anytime I'd fetch the document, I'd only want 2-3 fields ... based on arguments
Also, there'll be filters passed on to the back-end
Seems like a perfect use case for GraphQL

But the problem is that only a few attributes (~5-6) would be known beforehand.

@Vibhu-Agarwal
Vibhu-Agarwal / Promise-async-sync.js
Created March 21, 2020 09:13
Want to Successfully run test2
const calculate = k => new Promise((resolve, reject) => {
setTimeout(() => {
resolve(k**3)
}, 500)
})
const gimme_val = async (k) => {
transformed_val = await calculate(k)
return transformed_val
}
@Vibhu-Agarwal
Vibhu-Agarwal / Incorrect Solution1
Created November 15, 2019 15:09
M121 | Chapter 3 | Lab 3: $lookup stage
db.air_alliances.aggregate([
{
$lookup:
{
"from": "air_routes",
"foreignField": "airline.name",
"localField": "airlines",
"as": "route_docs"
}
},
@Vibhu-Agarwal
Vibhu-Agarwal / simple_server.py
Created October 16, 2019 09:09
A simple Flask Server with POST request.
## ----------------------------------------------------------------------------------------------- ##
## ---------------------------------- Necessary Flask Modules ------------------------------------ ##
from flask import Flask, render_template, request, jsonify, make_response
## ----------------------------------------------------------------------------------------------- ##
## ----------------------------------------------------------------------------------------------- ##
## --------------- Initialising the flask object and registering github blueprint ---------------- ##
app = Flask(__name__)
# Model dependent image size validation
# forms.py
from django import forms
from .models import *
from django.core.files.images import get_image_dimensions
class ValidateImageForm(forms.ModelForm):
class Meta:
@Vibhu-Agarwal
Vibhu-Agarwal / Django_unsignedBigint.py
Created May 30, 2019 08:58 — forked from pinfort/Django_unsignedBigint.py
Django database fields for using unsigned bigint column
from django.db import models
class PositiveBigIntergerRelDbTypeMixin(models.PositiveIntegerRelDbTypeMixin):
def rel_db_type(self, connection):
if connection.features.related_fields_match_type:
return self.db_type(connection)
else:
return models.BigIntegerField().db_type(connection=connection)
class PositiveBigIntegerField(PositiveBigIntegerRelDbTypeMixin, models.BigIntegerField):
@Vibhu-Agarwal
Vibhu-Agarwal / Login_Facebook.html
Created May 24, 2019 14:01
Login Facebook (Absolute Front-end based)
<!DOCTYPE html>
<html>
<head>
<title>Facebook Login JavaScript Example</title>
<meta charset="UTF-8">
</head>
<body>
<script>
// This is called with the results from from FB.getLoginStatus().
function statusChangeCallback(response) {
@Vibhu-Agarwal
Vibhu-Agarwal / models.py
Last active March 7, 2024 00:28
Example Describing How to Serialize Multiple Models through One Serializer (Case of Foreign Keys) | Django Rest Framework
from django.db import models
class ModelA(models.Model):
fieldA1 = models.CharField(max_length=100, unique=True)
fieldA2 = models.TextField(validators=[URLValidator()], blank=True, null=True)
fieldA3 = models.CharField(max_length=100, unique=True, null=True, blank=True)
field4 = models.BooleanField(default=True)