Skip to content

Instantly share code, notes, and snippets.

View brunopk's full-sized avatar

Bruno Piaggio brunopk

View GitHub Profile
@brunopk
brunopk / UseCombinedInfo.js
Created November 5, 2020 16:03
Custon hook to combine information from an HTTP service (using [useFetchSerial](https://snippets.cacher.io/snippet/881249469ca59cea7870)) and database (realm) in React Native
const useCombinedInfo = (id, combineInfo) => {
const {realm} = useContext(MainContext);
const [info, setInfo] = useState(null);
const [isLoading, setIsLoading] = useState(false);
const [isError, setIsError] = useState(false);
const [serviceInfo, serviceLoading, serviceError] = useFetchSerial(
[getResource],
[{id, filter}],
);
@brunopk
brunopk / Modal.js
Last active November 5, 2020 15:44
A modal component using styled components https://styled-components.com/ and react-native-modal
import React from 'react';
import Modal from 'react-native-modal';
import styled from 'styled-components/native';
import {View, StyleSheet} from 'react-native';
const styles = StyleSheet.create({
primaryContainer: {
height: '30%',
justifyContent: 'center',
alignItems: 'center',
@brunopk
brunopk / UseFetchSerial.js
Last active November 5, 2020 15:46
Custom hook to query an arbitrary number of services asynchronously and serially
import {useReducer, useEffect} from 'react';
const A_FETCH_INIT = 'FETCH_INIT';
const A_FETCH_SUCCESS = 'FETCH_SUCCESS';
const A_FETCH_FAILURE = 'FETCH_FAILURE';
const INITIAL_STATE = {
isLoading: false,
isError: false,
result: null,
};
@brunopk
brunopk / README.md
Last active October 23, 2020 01:37
Anaconda tips

Anaconda tips

This readme is for macOS and Anaconda installed with brew

Creating python virtual environment wiht specific python version and preinstalled libraries:

cd /usr/local/anaconda3/bin
./conda create -n myenv python=3.6 scipy=0.15.0 astroid babel
'use strict';
import React, {PureComponent} from 'react';
import {StyleSheet, View, Alert} from 'react-native';
import {RNCamera} from 'react-native-camera';
class Scanner extends PureComponent {
constructor(props) {
super(props);
this.state = {
navigation: props.navigation,
@brunopk
brunopk / StyledCard.js
Last active November 13, 2020 21:17
React Native component using styled components https://styled-components.com/
import React from 'react';
import styled from 'styled-components/native';
import {Color} from '../../styles';
import {IconButton} from './IconButton';
const MAX_STRING_LENGTH = 15;
const StyledView = styled.View`
flex: 1;
flex-direction: row;
@brunopk
brunopk / StyledTable.js
Created October 13, 2020 22:06
React Native component to show an editable table created with react-native-table-component
import React from 'react';
import styled from 'styled-components/native';
import {StyleSheet, TouchableOpacity, View} from 'react-native';
import {Icon} from 'react-native-elements';
import {Colors} from 'react-native/Libraries/NewAppScreen';
import {Color} from '../styles';
import {Table, Cell, Row, TableWrapper} from 'react-native-table-component';
const HEIGHT_HEADER_AND_BTN = 30;
@brunopk
brunopk / UseFetchParallel.js
Last active November 5, 2020 15:49
Custom hook to query an arbitrary number of services asynchronously and parallelly using promises and async-await
import {useReducer, useEffect} from 'react';
const A_FETCH_INIT = 'FETCH_INIT';
const A_FETCH_SUCCESS = 'FETCH_SUCCESS';
const A_FETCH_FAILURE = 'FETCH_FAILURE';
const INITIAL_STATE = {
isLoading: false,
isError: false,
result: null,
};
@brunopk
brunopk / UseFetchService.js
Last active October 28, 2020 22:28
Generic custom hook for querying services and update components asynchronously
import {useReducer, useEffect} from 'react';
const A_FETCH_SET_PARAM = 'FETCH_SET_PARAM';
const A_FETCH_INIT = 'FETCH_INIT';
const A_FETCH_SUCCESS = 'FETCH_SUCCESS';
const A_FETCH_FAILURE = 'FETCH_FAILURE';
const A_FETCH_FAILURE_RESET = 'FETCH_FAILURE_RESET';
const INITIAL_STATE = {
isLoading: false,
isError: false,
@brunopk
brunopk / jboss-web.xml
Last active August 24, 2020 16:05
Deploy Spring Boot aplication to JBoss EAP 7.3 or WildFly 18
<?xml version="1.0" encoding="UTF-8"?>
<!-- this is really not
> needed... you can just build (or rename WAR file to)
> spring-boot-jboss.war this file goes on src/main/webapp/WEB-INF/jboss-web.xml
> -->
<!DOCTYPE jboss-web>
<jboss-web>
<context-root>/app</context-root>
</jboss-web>