Skip to content

Instantly share code, notes, and snippets.

View calderaro's full-sized avatar

Angel Calderaro calderaro

View GitHub Profile
import {
MongoClientOptions,
MongoClient,
Db,
FilterQuery,
FindOneOptions,
OptionalId,
CollectionInsertOneOptions,
FindOneAndUpdateOption,
UpdateQuery,
@calderaro
calderaro / CustomError.ts
Created September 10, 2020 14:46
CustomError.ts
export default class CustomError extends Error {
code = '';
errors: { [key: string]: string[] } = {};
length = 0;
constructor(message: string, code: string) {
super(message);
this.code = code;
}
setError = (key: string, message: string) => {
@calderaro
calderaro / i18nReactSimulator.tsx
Last active August 26, 2020 18:26
i18n Simulator
// this is a simulation of react-i18n's API
import React, { ComponentType } from 'react';
import get from 'lodash/get';
import { Diff } from 'utility-types';
type Labels = { [key: string]: string };
export type WithTranslation = { t: (key: string) => string };
export const t = (labels: Labels) => (key: string): string => get(labels, key, key);
import React from 'react';
export interface AsyncHandlerProps<T> {
handler: () => Promise<T>;
children(res: {
state: State<T>;
execute: () => Promise<void>;
}): React.ReactNode;
}
@calderaro
calderaro / index.js
Created August 14, 2020 02:12
Chartjs React
import React from 'react';
import Chart, {ChartDataSets} from 'chart.js';
import styles from './styles';
interface Props {
labels: string[];
datasets: ChartDataSets[];
}
class Graph extends React.Component<Props> {
@calderaro
calderaro / jwtRS256.sh
Created July 6, 2020 23:04 — forked from ygotthilf/jwtRS256.sh
How to generate JWT RS256 key
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
cat jwtRS256.key
cat jwtRS256.key.pub
@calderaro
calderaro / index.tsx
Created June 10, 2020 20:13
select modal
import React from "react";
import { View, Text, Dimensions } from "react-native";
import Modal from "react-native-modal";
import { FontAwesomeIcon } from "@fortawesome/react-native-fontawesome";
import { TouchableOpacity } from "react-native-gesture-handler";
import { faCheckCircle, faCircle } from "@fortawesome/free-regular-svg-icons";
import styles from "./styles";
const { width } = Dimensions.get("window");
@calderaro
calderaro / Date.tsx
Last active June 1, 2020 00:35
React Inputs
import React from "react";
import DatePicker from "react-datepicker";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faQuestionCircle } from "@fortawesome/free-regular-svg-icons";
import "react-datepicker/dist/react-datepicker.css";
import styles from "./styles.module.css";
interface Props<Key> {
id: Key;
value?: Date | null;
async function createToken(tokenParams: CustomerCreateInput) {
const [month, year] = tokenParams.expiry.split('/');
const res = await fetch('https://api.conekta.io/tokens', {
method: 'POST',
body: JSON.stringify({
card: {
number: tokenParams.number.replace(/\s/g, ''),
cvc: tokenParams.cvc,
exp_month: month,
exp_year: year,
@calderaro
calderaro / FormHandler.tsx
Last active May 21, 2020 07:32
Async Handlers
import React from "react";
export interface FormHandlerChildrenProps<T> {
state: FormState<T>;
reload?: () => Promise<void>;
create?: () => Promise<void>;
update?: () => Promise<void>;
remove?: () => void;
onChange: (change: { id: string; value: any }) => void;
setModal: (name: string) => void;