Skip to content

Instantly share code, notes, and snippets.

View flavioribeirojr's full-sized avatar
:shipit:
debugging...

Flávio Ribeiro flavioribeirojr

:shipit:
debugging...
View GitHub Profile
@flavioribeirojr
flavioribeirojr / react-native-wsl2
Created August 16, 2021 14:49
Steps to run react-native using wsl2
# Windows
# First thing, install android-studio
# Powershell
adb kill-server
adb -a nodaemon server start
# WSL2 (Ubuntu)
cd android
./gradlew assembleDebug # assembleRelease for release builds
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}
$remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '"
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if ($found) {
@flavioribeirojr
flavioribeirojr / redux-dispatch-hook.jsx
Last active April 3, 2020 00:20
Example of the useDispatch hook
import React from 'react';
import { useDispatch } from 'react-redux';
import { addToCart } from './cart-actions';
const products = [
{
id: 1,
name: 'Coffe Bottle',
price: 29
}
@flavioribeirojr
flavioribeirojr / products-list-hook.jsx
Created April 1, 2020 00:54
Product List with Redux useSelector hook
import React from 'react';
import { useSelector } from 'react-redux';
function ProductList() {
const cart = useSelector(state => state.shop.cart);
return (
<div>
{
cart
@flavioribeirojr
flavioribeirojr / products-list.jsx
Created March 31, 2020 23:50
Redux Shop Store Access
import React from 'react';
import { connect } from 'react-redux';
function ProductList({ cart }) { // A prop cart foi injetada pelo HOC do React Redux
return (
<div>
{
cart
.map(cartProduct => (
<h1 key={cartProduct.id}>
@flavioribeirojr
flavioribeirojr / products-reducer.js
Created March 22, 2020 13:21
Using reduce to group an array of products by category
const products = [
{
name: 'Disposable Mask',
price: 8.75,
category: 'Health'
},
{
name: 'Painkiller',
price: 2.35,
category: 'Health'
@flavioribeirojr
flavioribeirojr / sum-reducer.js
Created March 21, 2020 13:36
Reducer basic example
const numbers = [5, 10, 15];
const sum = numbers.reduce((sum, number) => sum + number, 0)
// sum = 30
import React, { useState } from 'react'
import ReactDOM from 'react-dom';
function App() {
const [count, setCount] = useState(0)
function incrementCount() {
setCount(count + 1)
}
function createProduct({ name, price }) {
function getName() {
return name
}
function getPrice() {
return price
}
return {
function createCart() {
const data = {
items: []
}
function onItemAddedToCart() {
alert(`The cart has ${data.items.length} items`)
}
function addItem(item) {