Skip to content

Instantly share code, notes, and snippets.

View astrarudra's full-sized avatar
🎯
Focusing

Rudra Roy astrarudra

🎯
Focusing
View GitHub Profile
@astrarudra
astrarudra / UIComps.jsx
Created May 25, 2024 13:54
Zustand Controller - The UI
import { useOxyStore, OxyController } from
"src/shared-state"
import { Button , ControllerCard } from
'../UIElements'
export const ControllerTriggerButton = () => (
<Button onClick={() => OxyController.demo()}>
Run Controller
</Button>
@astrarudra
astrarudra / OxyController.js
Created May 25, 2024 13:47
Zustand Controller - Controller
import { useOxyStore } from "../OxyStore";
const { setState, setLoader } = useOxyStore.getState()
// ^ here, get all the functions ur need.
const generalController = { // Move this to a file
demo: async () => {
setLoader("Loading Gist Data")
const response = await fetch('https://gis....')
const json = await response.json()
setState({ demoData: json.data, fsLoader: null})
} // Clear Flow! No sideEffect Saga!
@astrarudra
astrarudra / GeneralSlice.js
Last active May 25, 2024 14:26
zustand-controller - Setup Slice
export const generalSlice = (set) => ({
fsLoader: null, // ur store variables
demoState: 0,
demoData: "I am connected to Store...",
/* Functions - let's not call them reducers,
brings back redux memories - yuck! 🤮 */
// Dynamic setState for root variables
setState: (data) => set((s: any) => {
Object.keys(data).forEach((key) => {
s[key] = data[key]
{
"data": "I am data from gist, API call was a success!"
}
@astrarudra
astrarudra / oxyStore.js
Last active May 25, 2024 13:34
zustand-controller - Setup Store
import { createWithEqualityFn }
from 'zustand/traditional'
import { immer } from 'zustand/middleware/immer'
import { shallow } from 'zustand/shallow'
/* I named it OxyStore - Using
createWithEqualityFn for Default Equality fn. */
const useOxyStore = createWithEqualityFn(
immer(// Immutable State & no return required.
(...o) => ({
...generalSlice(...o),
@astrarudra
astrarudra / ssa-version.json
Last active May 22, 2024 18:13
sadhansangha.org - SSA Version Json
{"version": "1.0"}
let intervalId;
let a = new Date();
let success = 0
const checkVersion = async () => {
try {
// Append the current timestamp to the URL to prevent caching
const response = await fetch(`https://gist.githubusercontent.com/astrarudra/c9a7783d2a4a334a192235d762a27c0d/raw?timestamp=${(new Date()).getTime()}`, {
cache: "no-store" // Also try to prevent cache on fetch request
});
@astrarudra
astrarudra / gist-raw-content-updatelatency.js
Last active May 20, 2024 20:35
This script checks the version of a JSON response from a gist raw API endpoint every 500 milliseconds to find out the update efficency
/**
* This script checks the version of a JSON response from a gist raw API endpoint every 500 milliseconds to find out the update efficency.
* Run this exactly update clicking update JSON, check my test.json jist. Clone it and modify the version.
* If the version is X, it logs the data. If the version is not X, it logs the current time, the version,
* and the time difference between the request initiation and the response reception.
* The script also ensures that the API response is not cached by appending a unique timestamp
* to each request URL and setting cache control options.
*/
let intervalId;
@astrarudra
astrarudra / test.json
Last active May 20, 2024 20:28
Testing
{
"version": 13
}
@astrarudra
astrarudra / greytHR-export-holiday-to-ical-sync.js
Last active May 11, 2024 13:12
This script exports greytHR holidays in iCal format, Used for syncing holidays to calendars - Apple, Google, Outlook, etc.
/*
Author: Rudra Roy
Description:
This script exports greytHR holidays in iCal format.
Used for syncing holidays to calendars - Apple, Google, Outlook, etc.
*/
// Constants for customizing holiday Reason
const prefix = 'Holiday: '
const optPostFix = ' (Optional)'