Skip to content

Instantly share code, notes, and snippets.

Avatar
🌌

Nicolas Sturm sturmenta

🌌
View GitHub Profile
@sturmenta
sturmenta / mac-config.md
Last active February 5, 2023 10:11
mac m1- start configuration
View mac-config.md
defaults write com.apple.dock autohide-delay -float 0; defaults write com.apple.dock autohide-time-modifier -int 0;killall Dock
  • show hide folders & files
defaults write com.apple.finder AppleShowAllFiles -bool YES && killall Finder
@sturmenta
sturmenta / stringifyWithCustomDepth.ts
Last active November 19, 2022 14:48
Version of JSON.stringify limitied to a specific depth.
View stringifyWithCustomDepth.ts
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 / removeHoursMinutesAndSecondsFromDate.ts
Created November 7, 2022 23:16
remove Hours Minutes And Seconds From Date
View removeHoursMinutesAndSecondsFromDate.ts
import dayjs from 'dayjs';
/**
* return DD/MM/YYYY
*/
export const removeHoursMinutesAndSecondsFromDate = (
date: Date,
): {newDate: dayjs.Dayjs; DDMMYYYY: string} => {
const _date = dayjs(date);
@sturmenta
sturmenta / validateAtLeast13Years.ts
Created November 7, 2022 23:11
validate user date greater than 13 years
View validateAtLeast13Years.ts
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 / 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"
View check-versionA-is-greater-or-equal-than-versionB.ts
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 / firestore2json.js
Last active October 28, 2022 19:03
firestore to json & json to firestore
View firestore2json.js
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 / example.ts
Last active October 28, 2022 18:29
get gist text - get gist raw text - fetch gist text
View example.ts
const gistUrl = 'https://gist.github.com/sturmenta/df1c9da1f219c88e996e48f19d57acd3';
const {data, error} = await getGistFirstFileText(`${gistUrl}.json`);
console.log(data);
// ## some title
//
// some text
@sturmenta
sturmenta / get-google-maps-place-by-autocomplete.ts
Last active October 19, 2022 11:31
get google maps place by autocomplete
View get-google-maps-place-by-autocomplete.ts
import Qs from 'qs';
import {GOOGLE_MAPS_API_KEY} from 'react-native-dotenv';
export const getGoogleMapsPlaceByAutocomplete = (
place: string,
): Promise<{
data?: {
predictions: Array<{
description: string;
place_id: string;
@sturmenta
sturmenta / scalable-image-uri.tsx
Created October 11, 2022 08:33
react-native uri-image with progress indicator
View scalable-image-uri.tsx
import React, {useState} from 'react';
import {ImageProps, View} from 'react-native';
import FastImage, {FastImageProps} from 'react-native-fast-image';
import {useComponentTrackTrace} from '_hooks';
import {ShowProgress} from '_atoms';
import {ToastShow} from '_utils';
import {getNewImageSizeByAspectRatio} from './get-new-image-size-by-aspect-ratio';
@sturmenta
sturmenta / show-progress.tsx
Created October 11, 2022 08:28
react-native progress indicator
View show-progress.tsx
import React from 'react';
import {useTheme} from '@react-navigation/native';
import {ProgressChart} from 'react-native-chart-kit';
import {MyThemeInterfaceColors, getPercentageInHex} from '_utils';
import {useComponentTrackTrace} from '_hooks';
interface ShowProgressProps {
progress: number;
height?: number;