Skip to content

Instantly share code, notes, and snippets.

View rdazvd's full-sized avatar
:octocat:

Rafael de Azevedo rdazvd

:octocat:
View GitHub Profile
@rdazvd
rdazvd / CsvFileReader.ts
Last active March 10, 2021 21:12
TypeScript CSV file reader class
import fs from 'fs';
export abstract class CsvFileReader<T> {
data: T[] = [];
constructor(public filename: string) {}
abstract mapRow(row: string[]): T;
read(): void {
@rdazvd
rdazvd / .babelrc
Last active February 2, 2021 20:46
Set up React Testing Library on a Next.js project
// This config file makes sure Jest is using Next.js's Babel preset.
{
"presets": ["next/babel"]
}
@rdazvd
rdazvd / Dropdown.js
Created February 1, 2021 15:52
React dropdown component with click outside event bubbling
import React, { useState, useEffect } from 'react';
const Dropdown = ({ options, label, selected, onSelectedChange }) => {
const [open, setOpen] = useState(false);
const ref = React.useRef();
useEffect(() => {
const onBodyClick = (event) => {
if (ref.current && ref.current.contains(event.target)) {
return;

Keybase proof

I hereby claim:

  • I am rdazvd on github.
  • I am rdazvd (https://keybase.io/rdazvd) on keybase.
  • I have a public key ASDFpN1iWnVhKGSLuldmpqU4Y7r2rmAuohWz_f54lunf2Qo

To claim this, I am signing this object:

@rdazvd
rdazvd / createDataContext.js
Created August 10, 2020 16:20
A React Context creator, handy to use for defining state management logic with the useReducer hook
import React from 'react';
export default (reducer, actions, initialState) => {
const Context = React.createContext();
const Provider = ({ children }) => {
const [state, dispatch] = React.useReducer(reducer, initialState);
const boundActions = {};
for (let key in actions) {
boundActions[key] = actions[key](dispatch);
@rdazvd
rdazvd / googleMapsInterfacing.ts
Created July 14, 2020 18:58
The most basic implementation of Google Maps interfacing with typescript
interface Mappable {
location: {
lat: number;
lng: number;
};
}
export class CustomMap {
private googleMap: google.maps.Map;
@rdazvd
rdazvd / debouncing.js
Created January 17, 2020 20:05
Versatile debouncing function (useful for dynamically calling functions triggered by frequent user events)
const debounce = (functionToBeCalled, delay = 1000) => {
let timeoutId;
return (...functionArgs) => {
if (timeoutId) clearTimeout(timeoutId);
timeoutId = setTimeout(
() => functionToBeCalled.apply(null, functionArgs),
delay
);
};
};
@rdazvd
rdazvd / typingDebounce.js
Created January 17, 2020 15:34
Basic typing event debounce
const fetchData = async () => {
...
};
let timeoutId;
const onInput = event => {
if (timeoutId) clearTimeout(timeoutId);
timeoutId = setTimeout(() => fetchData(event.target.value), 1000); // adjust debouncing time accordingly
};
@rdazvd
rdazvd / handleInputChange.js
Created November 6, 2019 18:22
boilerplate function for manipulating onChange events in React controlled inputs
// adapt setState function name and new state value according to your case
const handleInputChange = event =>
setState([event.target.name]: event.target.value);
@rdazvd
rdazvd / license.md
Created October 24, 2019 00:01
hippocratic license v1.1

Copyright (YEAR) (COPYRIGHT HOLDER)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

  • The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

  • The Software may not be used by individuals, corporations, governments, or other groups for systems or activities that actively and knowingly endanger, harm, or otherwise threaten the physical, mental, economic, or general well-being of individuals or groups in violation of the United Nations Universal Declaration of Human Rights (https://www.un.org/en/universal-declaration-human-rights/).

THE SOFTWARE IS PROVIDED "