Skip to content

Instantly share code, notes, and snippets.

View samipshah100's full-sized avatar
🕉️
Karma Yoga

samipshah100

🕉️
Karma Yoga
View GitHub Profile
const crypto = require('crypto');
// this generates a random 20 char string using upto the first 10 chars from the inputString.
// this is used to create a workspace id from workspace name so that the workspace namespace can be easily searchable amongst the pinecone vector database namespaces
function createRandomWorkspaceIdFromName(inputString) {
const alphanumericInput = inputString
.replace(/[^a-zA-Z0-9]/g, '')
.slice(0, 10);
const remainingLength = 20 - alphanumericInput.length;
const randomBytes = crypto.randomBytes(remainingLength * 2);
const randomAlphanumeric = randomBytes
git status
git add .
git commit -m "initial commit"
git push -u origin main
import React from 'react'
import {actionCreator} from '../../redux/actionCreators.js'
import { useFetchEffect } from '../../hooks/useFetchEffect'
const AnotherComponent = () => {
const url = 'https://anotherAPIEndpoint.com/route' // sample api
const data = useFetchEffect(actionCreator)
return <div className="AnotherComponent">{data.map(<div>{data.name}</div>)}</div>
import React from 'react'
import { useFetchEffect } from '../../hooks/useFetchEffect'
const AnotherComponent = () => {
const url = 'https://anotherAPIEndpoint.com/route' // sample api
const responseData = useFetchEffect(url)
const {isLoading, data} = responseData // destructure out the data from the hook
import React, { useEffect } from 'react'
import { useFetchEffect } from '../../hooks/useFetchEffect'
const DemoComponent = () => {
const url = 'https://jsonplaceholder.typicode.com/posts' // sample api
const data = useFetchEffect(url)
// (optional) you can add your own useEffects e.g.
import React, { useEffect } from 'react'
import { useFetchEffect } from '../../hooks/useFetchEffect'
const DemoComponent = () => {
const url = 'https://jsonplaceholder.typicode.com/posts' // sample api
const data = useFetchEffect(url)
return <div className="DemoComponent">{data.map(<div>{data.name}</div>)}</div>
import { useState, useEffect } from 'react'
import axios from 'axios'
export const useFetchEffect = (url) => {
const [isLoading, setIsLoading] = useState(false)
const [isError, setIsError] = useState(false)
const [responseData, setResponseData] = useState(null)
useEffect(() => {
const fetchData = async () => {
import React, { Fragment, useState, useEffect } from 'react'
import axios from 'axios'
function DemoComponent() {
const [data, setData] = useState()
const url = 'http://dummy.restapiexample.com/api/v1/employees' // sample api
const [isLoading, setIsLoading] = useState(false)
const [isError, setIsError] = useState(false)
useEffect(() => {
@samipshah100
samipshah100 / CategoryScreen.js
Last active June 7, 2020 09:34
Flipkart options menu
// All your menu options go here.
const [menuItems, setMenuItems] = useState([
{ id: '1', name: 'Age', },
{ id: '2', name: 'Price', },
])
// this holds the keys of the menuItems for the view to know which category is currently being rendered.
const [selectedItem, setSelectedItem] = useState('1')
<View style ={styles.content}>