Skip to content

Instantly share code, notes, and snippets.

View jagdishlove's full-sized avatar
🎯
Focus

Jagdish Singh Mehra jagdishlove

🎯
Focus
  • Cronj
  • Bangalore
View GitHub Profile
@jagdishlove
jagdishlove / gist:164b618c78060557a282779dedaa6ecf
Created July 24, 2024 19:09
Multi-select scrolls to top after selecting
Please use useCallback with MenuList. That will work.
const MenuList = useCallback((props: any) => {
return (
<components.MenuList {...props}>{props.children}</components.MenuList>
</Fragment>
);
}, []);
## adding multiple hours timedifference in javascript
function minutesToHours(minutes) {
const h = Math.floor(minutes / 60);
const m = minutes % 60;
return `${h}.${m < 10 ? "0" : ""}${m}`;
}
const totalMinutes = getTimesheetData?.reduce((sum, entry) => {
return sum + hoursToMinutes(entry.noOfHours);
Setting npm config set legacy-peer-deps true on the Git main branch will not affect other team members' local npm configurations. Each team member will still need to run the command on their local machines if they want to use the --legacy-peer-deps option.
However, you can create a .npmrc file and add it to the Git repository to share the legacy-peer-deps configuration setting with other team members. Here's how to do it:
Create a new file called .npmrc in the root directory of your Git repository.
Add the following line to the file:
javascript
Copy code
//If we have an array where we need to find any value correspond to id which will be in same array so this we can use
function getMeetingTypeById(id) {
for (let i=0; i<modules.length; i++) {
for (let j=0; j<modules[i].exercises.length; j++) {
if (modules[i].exercises[j].id === id) {
return modules[i].exercises[j].meeting_type;
}
}
}
//Milestones having nested array object which was very confusing for me making this gist so that people get confortable with map and reduce function.
const totalMeetings = milestones.map(o => o.exercises.map(i => i.exercise)).reduce((acc, m) => acc.concat(m)).sort()
const totalCcExercises = totalMeetings?.filter(x => x === 478 || x === 480 || x === 170 || x === 213).length //this will count total repeated number of 478, 480, 170 and 213
const totalHcExercises = totalMeetings?.filter(x => x === 477 || x === 481 || x === 171 || x === 214).length
const totalFaExercises = totalMeetings?.filter(x => x === 479 || x === 211).length
const totalCssExercises = totalMeetings?.filter(x => x === 482 || x === 218).length
const fafsaCssExercises = totalMeetings?.filter(x => x === 483 || x === 218).length
  1. This is for who want to run unfollow script in their instagram profile then you will get following list scroll till the end and you will find profile with no intraction at the end of you list this is will reverse your following list and then apply that script which will run from the top

  2. For reversing open your inspect element and check from where your all list rendering in that div you need to add new id="anything" and use that id in you console and replace element to your id and then call your function.

For unfollow script Click here

@jagdishlove
jagdishlove / useQuery_with_useEffect.md
Last active December 19, 2021 18:25
onPage reload useEffect with useQuery. for any component e.g Modal.

credit

I don't store return data from query to react state. I just feel like that's an anti-pattern. You should just use the returned data as it is like below:

const { loading, data, error } = useQuery(SOME_QUERY)

// If you absolutely need to cache the mutated data you can do the below. But
// most of the time you won't need to use useMemo at all.
const cachedMutatedData = useMemo(() =>{
mutation popupreferral($user_id:Int!, $popup_date:timestamptz!){
insert_show_referral_popup(objects:{
user_id:$user_id
popup_date:$popup_date
}on_conflict:{
constraint: show_referral_popup_pkey
update_columns:popup_date
}){
returning{
export const GET_FILES = gql`
query GetFiles {
files:files(where:{user_id:{_eq:439}}) {
...File
}
}
${FRAGMENTS}
`