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 / 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 / signInAfterGettingToken.js
Last active June 11, 2021 16:34
Get customToken from URL and login using signInWithCustomToken
// Mobile: React Native
import React, {useState, useEffect} from 'react';
import { View } from 'react-native';
import {Button} from 'react-native-paper';
import { WebView } from 'react-native-webview';
const App = () => {
const [show, setShow] = useState({isOpen: false, url: null});
@heytulsiprasad
heytulsiprasad / redirectOnResponse.js
Created June 11, 2021 16:29
Redirect user to route passing custom token as URL param
// Web: React
import { auth } from "./config/firebase";
auth.onAuthStateChanged((user) => {
if (user) {
user.getIdToken(true).then((idToken) => {
// This is where to call the API
const requestOptions = {
@heytulsiprasad
heytulsiprasad / obtainCustomToken.js
Created June 11, 2021 16:14
Express backed that sends out customtoken for verified users
// Backend: Node - Express
const express = require("express");
const admin = require("firebase-admin");
// Setup firebase admin [HERE]
// Route that handles GET request
app.post("/verify-token", (req, res) => {
@heytulsiprasad
heytulsiprasad / sendIdToken.js
Created June 11, 2021 16:04
Send the idToken after authentication to server to generate customToken
// Web: React
import { auth } from "./config/firebase";
auth.onAuthStateChanged((user) => {
if (user) {
user.getIdToken(true).then((idToken) => {
// This is where to call the API
const requestOptions = {
@heytulsiprasad
heytulsiprasad / WebViewInApp.js
Created June 11, 2021 15:58
Basic usage of React Native Webview
// Mobile: React Native
import React, {useState, useEffect} from 'react';
import { View } from 'react-native';
import {Button} from 'react-native-paper';
import { WebView } from 'react-native-webview';
const App = () => {
const [show, setShow] = useState({isOpen: false, url: null});
@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/'}} />