Skip to content

Instantly share code, notes, and snippets.

View j471n's full-sized avatar
💭
Building Something amazing...

Jatin Sharma j471n

💭
Building Something amazing...
View GitHub Profile
import concurrent.futures
from django.http import JsonResponse
def func1(param1, param2):
# Your function implementation
return f"result from func1 with {param1} and {param2}"
def func2(param1):
# Your function implementation
return f"result from func2 with {param1}"
"""
Author: Jatin Sharma
Working:
* It take the date from string input and converts that to the the short version
---- INPUT-----
- March 2022
- Mar'22
@j471n
j471n / useFetchWithSWR.ts
Created January 15, 2023 06:40
Custom Hooks
import useSWR from "swr";
// fetcher to fetch the data
// const fetcher = (...args) => fetch(...args).then((res) => res.json());
import fetcher from "@lib/fetcher";
export default function useFetchWithSWR(url: string) {
const { data, error } = useSWR(url, fetcher);
return {
@j471n
j471n / getPlatform.js
Created December 14, 2022 04:46
To get the platform using Javascript
function getOS() {
var userAgent = window.navigator.userAgent,
platform = window.navigator.platform,
macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'],
windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'],
iosPlatforms = ['iPhone', 'iPad', 'iPod'],
os = null;
if (macosPlatforms.indexOf(platform) !== -1) {
os = 'Mac OS';
@j471n
j471n / getFormattedDate.js
Created December 14, 2022 04:22
To Format a date
// Returns like: Dec 13, 2022
export function getFormattedDate(date) {
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'];
const newDate = new Date(date)
return `${months[newDate.getMonth()]} ${newDate.getDate()}, ${newDate.getFullYear()}`;
}

It makes text are auto grow

<textarea
  onInput={(e) => {
    e.target.style.height = "5px";
    e.target.style.height = e.target.scrollHeight + "px";
 }}
@j471n
j471n / Important Commands.md
Last active January 4, 2023 16:49
This contains the important and useful commands that you need while using git

Useful Git commands

Change branch Name in git

// If you're currently on the branch you want to rename-
git branch -m new_name 

// Or else-
git branch -m old_name new_name 
@j471n
j471n / DarkModeWithContextAPI.md
Created April 21, 2022 17:16
Create DarkMode Context API to handle the Theme switch in Next.js App

Darkmode with Context API in Next.js

Firstly create a file for context which will look like this-

// .../context/darkModeContext.js

import React, { useState, useContext, useEffect, createContext } from "react";
const DarkModeContext = createContext(undefined);
@j471n
j471n / Chef and Races (CHEFRACES).cpp
Last active March 27, 2022 09:53
Codechef March Long Two 2022, (Div 4) - Solution in C++
#include <bits/stdc++.h>
#define el "\n"
#define rep(i, a, b) for (int i = a; i < b; i++)
typedef long long ll;
using namespace std;
//---------------------- Solution Starts Here ----------------------
@j471n
j471n / cpSetup.cpp
Created March 15, 2022 06:41
Comepetive Programming C++ Code setup with input and output text file
#include <bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb(a) push_back(a)
#define fr(a,b) for(int i = a;i < b; i++)
typedef long long ll;
using namespace std;
void init_code(){