Skip to content

Instantly share code, notes, and snippets.

@intergalacticspacehighway
intergalacticspacehighway / cloudSettings
Last active November 2, 2020 12:03
useReducer with thunks and redux dev-tools.
{"lastUpload":"2020-11-02T12:03:38.255Z","extensionVersion":"v3.4.3"}
@intergalacticspacehighway
intergalacticspacehighway / App.tsx
Created December 11, 2021 04:32
React native pager view events with reanimated
import React from 'react';
import {View, StyleSheet, Text} from 'react-native';
import PagerView from 'react-native-pager-view';
import Animated, {useHandler, useEvent} from 'react-native-reanimated';
const AnimatedPager = Animated.createAnimatedComponent(PagerView);
export function usePagerScrollHandler(handlers, dependencies) {
const {context, doDependenciesDiffer} = useHandler(handlers, dependencies);
const subscribeForEvents = ['onPageScroll'];
@intergalacticspacehighway
intergalacticspacehighway / Timer in cpp
Last active December 26, 2021 07:24
Timer to measure performance in c++
#include <iostream>
#include <chrono>
class Timer
{
public:
Timer() {
startTimePoint = std::chrono::high_resolution_clock::now();
}
~Timer() {
@intergalacticspacehighway
intergalacticspacehighway / react-native+0.64.3.patch
Last active January 21, 2022 04:38
React native flex gap patch - only works on iOS
diff --git a/node_modules/react-native/Libraries/Components/View/ReactNativeViewViewConfig.js b/node_modules/react-native/Libraries/Components/View/ReactNativeViewViewConfig.js
index 4d6f0dd..e120116 100644
--- a/node_modules/react-native/Libraries/Components/View/ReactNativeViewViewConfig.js
+++ b/node_modules/react-native/Libraries/Components/View/ReactNativeViewViewConfig.js
@@ -13,104 +13,104 @@ import ReactNativeViewViewConfigAndroid from './ReactNativeViewViewConfigAndroid
import {Platform} from 'react-native';
const ReactNativeViewConfig = {
- uiViewClassName: 'RCTView',
+ uiViewClassName: "RCTView",
@intergalacticspacehighway
intergalacticspacehighway / App.tsx
Created January 7, 2022 06:18
Add row/col gaps in flatlist
function App() {
const data = Array(10).fill(0);
const GAP = 5;
const numColumns = 3;
const { width } = Dimensions.get("window");
// Reduce the size to accomodate margin space by items
const ITEM_SIZE = width / numColumns - ((numColumns - 1) * GAP) / numColumns;
const renderItem = ({ index }) => {
@intergalacticspacehighway
intergalacticspacehighway / useKeyboardBottomInset hook
Created August 10, 2021 04:54
Hook to get keyboard height in React Native and add bottom/padding inset on a view.
import { Keyboard, Platform, KeyboardEvent } from 'react-native';
const useKeyboardBottomInset = () => {
const [bottom, setBottom] = React.useState(0);
const subscriptions = React.useRef([]);
React.useEffect(() => {
function onKeyboardChange(e) {
if (
e.startCoordinates &&
@intergalacticspacehighway
intergalacticspacehighway / keyboard-aware-reanimated-scrollview.tsx
Last active March 17, 2023 12:13
keyboard aware reanimated scrollview
import React from "react";
import { Dimensions, TextInput, ScrollView } from "react-native";
import Animated, {
useAnimatedKeyboard,
useAnimatedReaction,
runOnJS,
KeyboardState,
useAnimatedProps,
useAnimatedScrollHandler,
@intergalacticspacehighway
intergalacticspacehighway / commands.txt
Last active April 12, 2023 07:38
Some commands for reference
// Remove node_modules, iOS Pods and android build in nested folders from current pwd
find . \( -type d -name "node_modules" -o -type d -path "*/ios/Pods" -o -type d -path "*/android/build" \) -exec rm -rf '{}' +
// command to approve "developer not verified error" executables from terminal
xattr -d com.apple.quarantine $(which <name-of-executable>)
// xcode build clean
xcodebuild clean -workspace ios/{projectName}.xcworkspace -scheme {projectName}
@intergalacticspacehighway
intergalacticspacehighway / use-fetch-on-app-foreground.tsx
Created January 28, 2022 04:10
app fetch request failing in background
import { useEffect, useRef } from "react";
import { AppState, AppStateStatus } from "react-native";
export const useFetchOnAppForeground = () => {
const listener = useRef(null);
function fetchOnAppForeground(params) {
if (AppState.currentState === "active") {
return fetch(params);
} else {
@intergalacticspacehighway
intergalacticspacehighway / gist:ad67264c41f65d52f11ef95e5934d50d
Last active November 13, 2023 19:14
Streaming text request in React Native PoC
import Networking from "react-native/Libraries/Network/RCTNetworking.ios";
// Same import from .android
// import Networking from "react-native/Libraries/Network/RCTNetworking.android";
let streamingServer = "Streaming Server URL";
let requestId = null;