Skip to content

Instantly share code, notes, and snippets.

View abhishek2x's full-sized avatar
💻
Either Optimising or Developing something...

Abhishek Srivastava abhishek2x

💻
Either Optimising or Developing something...
View GitHub Profile
@abhishek2x
abhishek2x / localStorage.js
Created July 26, 2020 11:44
This gist is created with an intention to clear the concepts of Local Storage in JavaScript.
const addItems = document.querySelector(".add-items");
const itemsList = document.querySelector(".plates");
const items = JSON.parse(localStorage.getItem("items")) || [];
function addItem(e) {
e.preventDefault();
// console.log('Hello');
const text = this.querySelector("[name=item]").value;
const item = {
text,
@abhishek2x
abhishek2x / localStorage-index.html
Last active August 1, 2020 09:36
Basic HTML for localStorage demonstration
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>LocalStorage</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
@abhishek2x
abhishek2x / localStorage-style.css
Last active August 1, 2020 09:37
Basic CSS Styling for localStorage demonstration
html {
box-sizing: border-box;
background: url("oh-la-la.jpeg") center no-repeat;
background-size: cover;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
font-family: Futura, "Trebuchet MS", Arial, sans-serif;
@abhishek2x
abhishek2x / DataFetching.js
Last active August 29, 2020 08:43
Using Axios with useEffect to fetch data in react
import React, { useState, useEffect } from "react";
import Axios from "axios";
function DataFetching() {
const [post, setPost] = useState({});
const [id, setId] = useState(1);
const [idFromButtomClick, setIdFromButtomClick] = useState(1);
const handleClick = () => {
setIdFromButtomClick(id);
@abhishek2x
abhishek2x / DataFetching2.js
Created August 29, 2020 08:46
Using Axios and useReducer to fetch data in React
import React, { useReducer, useEffect } from "react";
import axios from "axios";
const initialState = {
loading: true,
error: "",
post: {},
};
const reducer = (state, action) => {
@abhishek2x
abhishek2x / BinarySearch.cpp
Created November 29, 2020 09:24
Binary Search Algorithm
// C++ program to implement recursive Binary Search
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int binarySearch(int arr[], int l, int r, int x) {
while (l <= r) {
int m = l + (r - l) / 2;
@abhishek2x
abhishek2x / reversedSorted.cpp
Last active November 29, 2020 10:07
Binary Search algorithm on a reversed sorted array.
// Binary Search algorithm on a reversed sorted array.
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
ios :: sync_with_stdio(false);
cin.tie(0);
@abhishek2x
abhishek2x / Occurance.cpp
Created November 29, 2020 10:12
Finding First and Last Occurance an Element in a Sorted Array.
// Finding First and Last Occurance an Element in a Sorted Array
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
ios :: sync_with_stdio(false);
cin.tie(0);
@abhishek2x
abhishek2x / Floor.cpp
Created November 29, 2020 10:17
Finding Floor of an Element in a Sorted array
/*!
* Finding Floor of an Element in a Sorted array
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
@abhishek2x
abhishek2x / Ceil.cpp
Created November 29, 2020 10:17
Finding Ceil of an Element in a Sorted array
/*!
* Finding Ceil of an Element in a Sorted array
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){