Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
Either Optimising or Developing something...

Abhishek Srivastava abhishek2x

💻
Either Optimising or Developing something...
View GitHub Profile
@abhishek2x
abhishek2x / Occurance.cpp
Created Nov 29, 2020
Finding First and Last Occurance an Element in a Sorted Array.
View Occurance.cpp
// 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 / reversedSorted.cpp
Last active Nov 29, 2020
Binary Search algorithm on a reversed sorted array.
View reversedSorted.cpp
// 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 / BinarySearch.cpp
Created Nov 29, 2020
Binary Search Algorithm
View BinarySearch.cpp
// 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 / DataFetching2.js
Created Aug 29, 2020
Using Axios and useReducer to fetch data in React
View DataFetching2.js
import React, { useReducer, useEffect } from "react";
import axios from "axios";
const initialState = {
loading: true,
error: "",
post: {},
};
const reducer = (state, action) => {
@abhishek2x
abhishek2x / DataFetching.js
Last active Aug 29, 2020
Using Axios with useEffect to fetch data in react
View DataFetching.js
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 / localStorage-style.css
Last active Aug 1, 2020
Basic CSS Styling for localStorage demonstration
View localStorage-style.css
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 / localStorage-index.html
Last active Aug 1, 2020
Basic HTML for localStorage demonstration
View localStorage-index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>LocalStorage</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
@abhishek2x
abhishek2x / localStorage.js
Created Jul 26, 2020
This gist is created with an intention to clear the concepts of Local Storage in JavaScript.
View localStorage.js
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,