Skip to content

Instantly share code, notes, and snippets.

View sturmenta's full-sized avatar
🌌

Nicolas Sturm sturmenta

🌌
  • Argentina
  • 22:20 (UTC -03:00)
View GitHub Profile
@sturmenta
sturmenta / example.ts
Last active October 28, 2022 18:29
get gist text - get gist raw text - fetch gist text
const gistUrl = 'https://gist.github.com/sturmenta/df1c9da1f219c88e996e48f19d57acd3';
const {data, error} = await getGistFirstFileText(`${gistUrl}.json`);
console.log(data);
// ## some title
//
// some text
@sturmenta
sturmenta / firestore2json.js
Last active October 28, 2022 19:03
firestore to json & json to firestore
const admin = require('firebase-admin');
const fs = require('fs');
const serviceAccount = require('../../../../../../Private/myschool-data_transfer-key.json');
admin.initializeApp({ credential: admin.credential.cert(serviceAccount) });
const schema = require('./schema').schema;
const firestore2json = (db, schema, current) => {
@sturmenta
sturmenta / check-versionA-is-greater-or-equal-than-versionB.ts
Created October 29, 2022 03:03
check version "A" is greater or equal than version "B"
export const checkVersionAIsGreaterOrEqualThanVersionB = ({
versionA,
versionB,
}: {
versionA: string; // 1.2.3
versionB: string; // 1.2.3
}): boolean => {
const _versionA = {
major: parseInt(versionA.split('.')[0], 10), // 1.2.3 -> 1
minor: parseInt(versionA.split('.')[1].split('.')[0], 10), // 1.2.3 -> 2
@sturmenta
sturmenta / validateAtLeast13Years.ts
Created November 7, 2022 23:11
validate user date greater than 13 years
import dayjs from 'dayjs';
export const validateAtLeast13Years = (DDMMYYYY?: string): boolean => {
if (!DDMMYYYY) return false;
const timePickerDate = DDMMYYYY.split('/').reverse().join('-');
const date1 = dayjs();
const date2 = dayjs(timePickerDate);
const diff = date1.diff(date2, 'years');
@sturmenta
sturmenta / removeHoursMinutesAndSecondsFromDate.ts
Created November 7, 2022 23:16
remove Hours Minutes And Seconds From Date
import dayjs from 'dayjs';
/**
* return DD/MM/YYYY
*/
export const removeHoursMinutesAndSecondsFromDate = (
date: Date,
): {newDate: dayjs.Dayjs; DDMMYYYY: string} => {
const _date = dayjs(date);
@sturmenta
sturmenta / stringifyWithCustomDepth.ts
Last active November 19, 2022 14:48
Version of JSON.stringify limitied to a specific depth.
export const stringifyWithCustomDepth = (obj: any, depth = 1): string => {
return !obj
? JSON.stringify(obj, null, 2)
: typeof obj === 'object'
? JSON.stringify(
JSON.parse(
depth < 1
? '"???"'
: `{${Object.keys(obj)
.map((k) => `"${k}": ${stringifyWithCustomDepth(obj[k], depth - 1)}`)
@sturmenta
sturmenta / plausible.ts
Last active May 28, 2023 16:29
plausible react-native expo config
import Plausible, { EventOptions, PlausibleOptions } from 'plausible-tracker';
import { setLocationHref } from '@expo/metro-runtime/build/location/Location.native.js';
// NOTE: see tracking events here: https://plausible.io/asd.xyz
const runPlausibleInitialConfig = () => {
let alreadyRun = false;
if (!alreadyRun) {
alreadyRun = true;
@sturmenta
sturmenta / WeekdaysSelector.tsx
Created June 12, 2023 03:53
react native WeekdaysSelector
import { TouchableOpacity, View } from 'react-native';
import { withLightHapticFeedback } from '_utils';
import { C_Text } from './C_Text';
const weekdays = ['L', 'M', 'X', 'J', 'V', 'S', 'D'];
export const WeekdaysSelector = ({
selectedDays,
@sturmenta
sturmenta / dist2GPS.ts
Last active June 16, 2023 23:29
Distance between two gps locations
const numToRad = (num) => (num * Math.PI) / 180;
export const getDistFrom2GpsLocations = ({ lat1, long1, lat2, long2 }) => {
lat1 = parseFloat(lat1);
long1 = parseFloat(long1);
lat2 = parseFloat(lat2);
long2 = parseFloat(long2);
const R = 6371e3;
const φ1 = numToRad(lat1);
@sturmenta
sturmenta / feedback.tsx
Last active August 29, 2023 18:20
react native collapse animation dynamic height
import React, {useEffect, useImperativeHandle, useState} from 'react';
import {Keyboard, View} from 'react-native';
import {useTheme} from '@react-navigation/native';
import {useSpring, animated} from '@react-spring/native';
import {MyThemeInterfaceColors} from '_styles';
import {GetDimensions} from '_atoms';
import {MultilineTextInput, Button, TextInputRef} from '_molecules';
import {getPercentageInHex, themedStyleSheet} from '_utils';
import {usePrevious} from '_hooks';