Skip to content

Instantly share code, notes, and snippets.

View EduVencovsky's full-sized avatar
🎯
Focusing

Eduardo Vencovsky EduVencovsky

🎯
Focusing
View GitHub Profile
@EduVencovsky
EduVencovsky / TodoList.tsx
Created August 1, 2020 14:11
Todo List com React Hooks, Typescript e Material-UI
import React, { useState } from 'react'
import { TextField, IconButton } from '@material-ui/core'
import AddIcon from '@material-ui/icons/Add'
import DeleteIcon from '@material-ui/icons/Delete'
interface TodoItem {
id: number
value: string
}
@EduVencovsky
EduVencovsky / ga.ipynb
Last active April 19, 2020 19:47
Use um AG para encontrar o ponto máximo da função: f(x) = x^2 sendo 0 <= x <= 31 e x é inteiro
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@EduVencovsky
EduVencovsky / CustomAttributeHelper.cs
Last active June 17, 2021 08:01
Helper to get custom attributes from a property with Blazor
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace ADD_YOUR_NAME_SPACE_HERE
{
public static class CustomAttributeHelper
{
public static MemberInfo GetExpressionMember<T>(Expression<Func<T>> accessor)
@EduVencovsky
EduVencovsky / RotateView.js
Created November 13, 2019 01:15
Component for creating a rotating View in React Native
import React, { useEffect, useState } from 'react'
import PropTypes from 'prop-types'
import { Animated, Easing } from 'react-native'
const RotateView = ({ rotate, degree, initialDegree, duration, children, ...otherProps }) => {
const [rotateValue] = useState(new Animated.Value(0))
useEffect(() => {
const toValue = rotate ? 1 : 0
@EduVencovsky
EduVencovsky / useNavigationFocusChanged.js
Last active November 8, 2019 01:08
React Hooks to listen to navigation didFocus event
import { useState, useEffect, useRef } from 'react'
export const useNavigationFocusChanged = (navigation, event) => {
const [focus, setFocus] = useState(false)
const listener = useRef(null)
useEffect(() => {
const changeFocus = () => {
setFocus(prev => !prev)
}
listener.current = navigation.addListener(event, changeFocus)
@EduVencovsky
EduVencovsky / index.html
Created October 22, 2019 18:52
CSS Scale Transition
<button id="open">open</button>
<div class="box scale">
<h1>
hey
</h1>
</div>
import { useState } from 'react'
export default function useToggle(defaultValue){
const [state, setState] = useState(defaultValue)
const toggle = (value = null) => {
if(value == null)
setState(!state)
else
setState(!!value)
@EduVencovsky
EduVencovsky / useAsyncStorage.js
Last active April 27, 2022 07:33
React Native hook for keeping the state in sync with AsyncStorage
import { useState, useEffect } from 'react'
import AsyncStorage from '@react-native-community/async-storage'
const useAsyncStorage = (key, initialValue) => {
const [hasLoad, setHasLoad] = useState(false)
const [data, setData] = useState(initialValue)
const set = async newData => {
setData(newData)
return newData === null ?
import { useState, useEffect } from 'react'
import Realm from '../database/migrations'
function reducer(action, { realm, name, queryObjects }) {
switch (action.type) {
case 'create':
return new Promise((resolve, reject) => {
try {
realm.write(() => {
resolve(realm.create(name, action.data))
@EduVencovsky
EduVencovsky / useTimeout.js
Created July 13, 2019 14:25
React hook for setTimeout
import { useEffect, useRef, useState } from 'react'
// The callback should setState so it will re trigger the timeout
function useTimeout(callback, delay) {
const savedCallback = useRef()
const [callBackCleanUp, setCallBackCleanUp] = useState(null)
// Remember the latest callback.
useEffect(() => {
savedCallback.current = callback
}, [callback])