Skip to content

Instantly share code, notes, and snippets.



  • The code defines a StoreProvider component that is intended to be used as a top-level component in a React application to manage the global state.
  • The component uses the React Hooks useState to initialize the state with the initialData prop passed in and to manage updates to the state using the dispatch method.
  • The component also defines three methods for working with a pub-sub pattern: publish, subscribe, and unsubscribe.
  • publish(topic: string, args: any) : this method will take in a topic and data, it will log the topic with the data being published and it will search for the subscribers of the topic if any, and call the callback for all the subscribers
  • subscribe(topic: string, func: (topic: string, data: any) => void) : this method will take in a topic and callback function, it will log the topic the client has subscribed to and it will save the topic and the callback along with unique token to know which subscription is which and which subscription to unsubscribe later.

>* uns

View typescript-example.ts
import { sum } from '../../src/foo'
describe('TypeScript spec', () => {
it('works', () => {
cy.wrap('foo').should('equal', 'foo')
it('calls TS source file', () => {
expect(sum(1, 2, 3, 4)).to.equal(10)
View cypress-run-parallel-scripts.js
//We're running the npm-run-all package to run the scripts independently for TDD/BDD test cases without dockerization and can help in to CI pipelines without overhead of getting all the scripts running sequentially or serially.
//This will parallely execute all the test-scripts files
"app-one": "cypress open --env configFile=script-one.local.json, isCI=false --config video=false"
"app-two": "cypress open --env configFile=script-two.local.json, isCI=false --config video=false"
"app-three": "cypress open --env configFile=script-three.local.json, isCI=false --config video=false"
"run-all-scripts-parallel": "npm-run-all --parallel app-two app-three"
View kubectl-nginx deployment
533 minikube status
534 kubectl version
535 kubectl get nodes
536 kubectl api-resources
537 kubectl api-versions
538 clear
539 kubectl get pods
540 kubectl get deployments
541 kubectl run nginx --image=nginx
542 kubectl get pods
View cypress-dependent-dropdown.js
it.only('Cowin State Chooser', function () {
cy.intercept('GET', '**/location/districts/2').as('Location');
cy.xpath("//div[text()='Search by District']")
.scrollIntoView({ offset: { top: -200, left: 0 }, easing: 'linear', duration: 1000, })
View api-client0window.js
function client(endpoint, customConfig = {}) {
const config = {
method: 'GET',
return window
.fetch(`${process.env.REACT_APP_API_URL}/${endpoint}`, config)
.then(async response => {
const data = await response.json()
View users.json
"_id" : ObjectId("5f9a940f9d32533a3dc9b2d6"),
"gender" : "male",
"name" : {
"first" : "john",
"last" : "doe"
"location" : {
"coordinates" : {
"latitude" : "-10.5930",
View .gitignore-reactjs
# See for more about ignoring files.
# dependencies
# testing
View student.json
"_id" : ObjectId("5f9a940f9d32533a3dc9b2d6"),
"gender" : "male",
"name" : {
"first" : "john",
"last" : "doe"
"location" : {
"coordinates" : {
"latitude" : "-10.5930",
View apollo_client.ts
import { ApolloClient, InMemoryCache } from "@apollo/client";
import { NextPageContext } from "next";
import React from "react";
import App from "next/app";
import Head from "next/head";
import { ApolloProvider } from "@apollo/client";
// On the client, we store the Apollo Client in the following variable.