Skip to content

Instantly share code, notes, and snippets.

View vbylen's full-sized avatar
:bowtie:
thankful for health & family

vbylen

:bowtie:
thankful for health & family
View GitHub Profile
@kyaroru
kyaroru / expo-config-plugin-modify-pod.ts
Last active May 11, 2024 07:52
Example of expo config plugin for modifying Podfile
import { ConfigPlugin, withDangerousMod } from '@expo/config-plugins'
import {
MergeResults,
mergeContents,
removeContents,
} from '@expo/config-plugins/build/utils/generateCode'
import path from 'path'
import fs from 'fs-extra'
const debug = require('debug')('file-viewer-plugin') as typeof console.log
function Favorite({
postId = null,
isLiked: _isLiked = false,
numberOfLikes: _numberOfLikes = 0,
}) {
const [isLiked, setIsLiked] = React.useState(_isLiked);
const [numberOfLikes, setNumberOfLikes] = React.useState(_numberOfLikes ?? 0);
const likeDebounceRef = React.useRef();
const lastIsLikedStateRef = React.useRef(_isLiked);
@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,
@FelixZY
FelixZY / supabase_api_auth.sql
Last active July 30, 2024 08:42
How to configure Supabase (https://supabase.com/) to generate and accept API tokens.
-- Token Based API Access for Supabase
--
-- How to configure Supabase (https://supabase.com/) to generate and accept API tokens.
--
-- (c) 2022 Felix Zedén Yverås
-- Provided under the MIT license (https://spdx.org/licenses/MIT.html)
--
-- Disclaimer: This file is formatted using pg_format. I'm not happy with the result but
-- prefer to follow a tool over going by personal taste.
--
@suhodolskiy
suhodolskiy / contrasting.ts
Last active March 30, 2024 03:41
Contrasting color [Colord]
import { Plugin } from 'colord'
declare module 'colord/colord' {
interface Colord {
contrasting(): Colord
}
}
const plugin: Plugin = (ColordClass) => {
ColordClass.prototype.contrasting = function () {
import { createContext, forwardRef, useCallback, useMemo } from "react";
import { FlatList, FlatListProps, ViewToken } from "react-native";
import Animated, { useSharedValue } from "react-native-reanimated";
const MAX_VIEWABLE_ITEMS = 4;
type ViewabilityItemsContextType = string[];
export const ViewabilityItemsContext = createContext<
Animated.SharedValue<ViewabilityItemsContextType>
@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 / 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'];
@cesargdm
cesargdm / DateTimePicker.web.ts
Last active June 1, 2022 00:55
DateTimePicker.web.ts
// DateTimePicker.web.ts
import React, { useEffect, useRef, ReactElement } from 'react'
import { TextInput } from 'react-native'
import { format } from 'date-fns'
interface Props {
minimumDate: Date
maximumDate: Date
value: string
onChange: (value: string) => void
@kjmph
kjmph / A_UUID_v7_for_Postgres.sql
Last active July 29, 2024 01:55
Postgres PL/pgSQL function for UUID v7 and a bonus custom UUID v8 to support microsecond precision as well. Read more here: https://datatracker.ietf.org/doc/draft-peabody-dispatch-new-uuid-format/
-- Based off IETF draft, https://datatracker.ietf.org/doc/draft-peabody-dispatch-new-uuid-format/
create or replace function uuid_generate_v7()
returns uuid
as $$
begin
-- use random v4 uuid as starting point (which has the same variant we need)
-- then overlay timestamp
-- then set version 7 by flipping the 2 and 1 bit in the version 4 string
return encode(