Skip to content

Instantly share code, notes, and snippets.

View Stringsaeed's full-sized avatar
🏗️
building something that matters

Muhammad Saeed Stringsaeed

🏗️
building something that matters
View GitHub Profile
@Stringsaeed
Stringsaeed / textrank.py
Created February 12, 2019 15:51
This is a naive implementation of textrank algorithm to summarize some text, I just looking for edits
import re
import string
import networkx as nx
from nltk import pos_tag
from nltk.corpus import stopwords
from nltk.stem import WordNetLemmatizer
from textblob.wordnet import NOUN, VERB, ADJ, ADV
from sklearn.metrics.pairwise import cosine_similarity
_WORD_PAT = r"\w[\w']{3,}"
import { useCallback, useState } from 'react';
// Usage
function App() {
// Call the hook which returns, current value and the toggler function
const [isTextChanged, setIsTextChanged] = useToggle();
return (
<button onClick={setIsTextChanged}>{isTextChanged ? 'Toggled' : 'Click to Toggle'}</button>
import {
DatabaseInterface,
ConnectionInformations,
CreateUser,
User as AccountsUser,
} from '@accounts/types';
import {
PrismaClient,
Prisma,
User,
@Stringsaeed
Stringsaeed / pixel.ts
Last active February 19, 2022 20:06
Create a pixel perfect design in react native
import {Dimensions} from 'react-native';
const {height: SCREEN_HEIGHT, width: SCREEN_WIDTH} = Dimensions.get('window');
const designSize = {width: 390, height: 844};
const CURRENT_RESOLUTION = Math.sqrt(
SCREEN_HEIGHT * SCREEN_HEIGHT + SCREEN_WIDTH * SCREEN_WIDTH,
);
const DESIGN_RESOLUTION = Math.sqrt(
designSize.height * designSize.height + designSize.width * designSize.width,
@Stringsaeed
Stringsaeed / phone-validation.ts
Created February 19, 2022 20:07
Phone validation using google lib phone number
import {PhoneNumberUtil} from 'google-libphonenumber';
export const isPhoneNumber = (number?: string) => {
try {
if (!number) {
throw new Error('Phone number is required');
}
if (number.length < 4) {
throw new Error('Phone number is too short');
}
@Stringsaeed
Stringsaeed / useRenderItem.tsx
Last active July 15, 2023 21:00
Render Item Hook to use in flatlists in react-native
import React, { useCallback } from "react";
import { ListRenderItem } from "react-native";
type BaseProps<T extends unknown> = {
item: T;
};
type UseRenderItemProps<T, P extends BaseProps<T>> = {
Component: React.ComponentType<P>;
componentProps: Omit<P, "item">;
@Stringsaeed
Stringsaeed / useScrollHandler.ts
Created February 19, 2022 20:09
react native reanimated scroll handler in y axies only
import {
useSharedValue,
useAnimatedScrollHandler,
} from 'react-native-reanimated';
const useScrollHandler = () => {
const scrollY = useSharedValue(0);
const onScroll = useAnimatedScrollHandler(event => {
scrollY.value = event.contentOffset.y;
});
@Stringsaeed
Stringsaeed / Fonts.ts
Created February 19, 2022 20:11
Generic Fonts to use across react native app
import {Platform, StyleSheet, TextStyle} from 'react-native';
import {getDesignSize} from '@utils';
type Weight = '700' | '600' | '500' | '400';
const fonts = new Map<Weight, string>([
['700' as const, Platform.select({default: '700' as const, android: 'Bold'})],
[
'500' as const,
@Stringsaeed
Stringsaeed / useAnimatedStatusBar.ts
Created February 19, 2022 20:14
react native animated status bar hook
import {StatusBar} from 'react-native';
import {useCallback} from 'use-memo-one';
import {useFocusEffect} from '@react-navigation/native';
import Animated, {runOnJS, useDerivedValue} from 'react-native-reanimated';
const updateStatusBarStyle = (
shared: Animated.SharedValue<number>,
maxNo: number,
) => {
'worklet';
@Stringsaeed
Stringsaeed / useFocusStatusBar.tsx
Created February 19, 2022 20:15
react native with react navigation focuse effect for status bar
import {useCallback} from 'react';
import {useFocusEffect} from '@react-navigation/native';
import {ColorValue, StatusBar, StatusBarStyle, Platform} from 'react-native';
const useFocusStatusBar = (
barStyle: StatusBarStyle = 'dark-content',
translucent: boolean = true,
backgroundColor: ColorValue = 'transparent',
): void => {
useFocusEffect(