Skip to content

Instantly share code, notes, and snippets.

View heytulsiprasad's full-sized avatar
⚛️
Overreacting

Tulsi Prasad heytulsiprasad

⚛️
Overreacting
View GitHub Profile
@heytulsiprasad
heytulsiprasad / useNonInitialHook.js
Last active October 27, 2021 13:05
Custom hook that doesn't run on initial render
import { useRef, useEffect } from "react";
const useNonInitialEffect = (effect, deps = []) => {
const initialRender = useRef(true);
useEffect(() => {
let effectReturns = () => {};
if (initialRender.current) {
initialRender.current = false;
import React from "react";
import { connect } from "react-redux";
import { loadMoreChatrooms } from "actions";
import AllChatrooms from "./AllChatrooms";
const Profile = ({ chatrooms, loadMoreChatrooms }) => {
return (
<div>
<AllChatrooms chatrooms={chatrooms} />
@heytulsiprasad
heytulsiprasad / timeDifference.js
Created September 22, 2021 04:42
Shows how to calculate difference in execution time in react native
console.log(JSON.stringify({ filter }, null, 4));
const start = new Date().getTime();
const end = new Date().getTime();
const time = end - start;
console.log({
inLength: filteredChatrooms.length,
filterTime: time,
@heytulsiprasad
heytulsiprasad / pthread.c
Last active September 2, 2021 09:21
Pthread examples
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> //Header file for sleep(). man 3 sleep for details.
#include <pthread.h>
// A normal C function that is executed as a thread
// when its name is specified in pthread_create()
void *myThreadFun(void *vargp)
{
sleep(4);
@heytulsiprasad
heytulsiprasad / activealiases.sh
Created August 17, 2021 15:18 — forked from virajkulkarni14/activealiases.sh
List of active aliases on Oh my zsh
-='cd -'
...=../..
....=../../..
.....=../../../..
......=../../../../..
1='cd -'
2='cd -2'
3='cd -3'
4='cd -4'
5='cd -5'
{
"eslint.options": {
"rules": {
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
]
}
@heytulsiprasad
heytulsiprasad / FirstWebViewComponent.js
Last active June 14, 2021 13:03
Basic usage of React Native Webview inside a component
import React from 'react';
import {SafeAreaView, StatusBar} from 'react-native';
import {WebView} from 'react-native-webview';
const App = () => {
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView style={{flex: 1}}>
<WebView source={{uri: 'https://medium.com/'}} />
@heytulsiprasad
heytulsiprasad / getAuthProviderResponse.json
Last active June 14, 2021 12:47
Response given by Auth Provider API
{ "tenantId": "some-random-tenant", "provider": "third.party" }
@heytulsiprasad
heytulsiprasad / signInWithAuthProvider.js
Last active June 11, 2021 16:55
Basic sign in using third party auth provider using Firebase
export const signInUserWithAuthProvider = async (
authProvider: AuthProvider
) => {
firebase.auth().tenantId = authProvider.tenantId;
const provider = new firebase.auth.SAMLAuthProvider(authProvider.provider);
firebase.auth().signInWithRedirect(provider);
const authResult = await firebase.auth().getRedirectResult();
return authResult;
@heytulsiprasad
heytulsiprasad / signInUserWithFirebase.js
Last active June 11, 2021 16:55
Basic email and password signin with Firebase
const signInUser = () => {
return firebase.auth().signInWithEmailAndPassword(email, password);
}