Skip to content

Instantly share code, notes, and snippets.

View vcapretz's full-sized avatar
🐿️

Vitor Capretz vcapretz

🐿️
View GitHub Profile
@vcapretz
vcapretz / latency.txt
Created June 11, 2022 23:08 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@vcapretz
vcapretz / test.spec.ts
Created November 17, 2021 12:43
mocking dates with `jest` and `mockdate`
beforeEach(() => {
Mockdate.set('2021-06-27T21:32:09.419Z');
});
afterEach(() => {
Mockdate.reset();
});
@vcapretz
vcapretz / instagram-like-button.jsx
Created January 15, 2021 14:00
A simple Like button with a nice animation using react-native-reanimated v2, support for my post in https://vcapretz.com/2021/instagram-button-react-native
import React from "react";
import Animated, {
useSharedValue,
withSpring,
useAnimatedStyle,
Extrapolate,
interpolate,
} from "react-native-reanimated";
import { Pressable, View, Button, StyleSheet } from "react-native";
import { MaterialCommunityIcons } from "@expo/vector-icons";
@vcapretz
vcapretz / reduce-motion-check.js
Created July 30, 2020 09:38
Small gist to showcase the usage of isReduceMotionEnabled with react-native-reanimated to disable animations
import React, { useState, useEffect } from "react";
import { AccessibilityInfo, View, Text } from "react-native";
import Animated from "react-native-reanimated";
const { block, cond, eq, useCode } = Animated;
const App = () => {
const [reduceMotionEnabled, setReduceMotionEnabled] = useState(false);
useEffect(() => {
// todos.js
import { createSlice } from '@reduxjs/toolkit'
const todosSlice = createSlice({
name: 'todos',
initialState: [],
reducers: {
addTodo(state, action) {
const { id, text } = action.payload
state.push({ id, text, completed: false })
import { createSlice, configureStore } from '@reduxjs/toolkit'
const todosSlice = createSlice({
name: 'todos',
initialState: [],
reducers: {
addTodo(state, action) {
const { id, text } = action.payload
state.push({ id, text, completed: false })
},
import { createStore, combineReducers } from 'redux'
import { authentication, todos } from './reducers'
const rootReducer = combineReducers({
authentication,
todos
})
const store = createStore(rootReducer)
import { createAction, createReducer, configureStore } from '@reduxjs/toolkit'
const addTodo = createAction('ADD_TODO')
const toggleTodo = createAction('TOGGLE_TODO')
const todos = createReducer([], {
[addTodo]: (state, action) => {
const todo = action.payload
return [...state, todo]
},
import { createAction, createReducer, configureStore } from '@reduxjs/toolkit'
const addTodo = createAction('ADD_TODO')
const toggleTodo = createAction('TOGGLE_TODO')
const todos = createReducer([], {
[addTodo]: (state, action) => {
const { id, text } = action.payload
state.push({ id, text, completed: false })
},
@vcapretz
vcapretz / redux-toolkit-example.js
Created January 19, 2020 15:54
Snippet used for showing an example in a blog post about Redux toolkit
import { createAction, createReducer, configureStore } from '@reduxjs/toolkit'
const increment = createAction('INCREMENT')
const decrement = createAction('DECREMENT')
const counter = createReducer(0, {
[increment]: state => state + 1,
[decrement]: state => state - 1
})