Skip to content

Instantly share code, notes, and snippets.

View julioxavierr's full-sized avatar
🦄
raising unicorns

Julio Xavier julioxavierr

🦄
raising unicorns
  • Brazil
View GitHub Profile
@julioxavierr
julioxavierr / ts-migrate.js
Created January 27, 2022 20:59
Migrate JS file to TS
var join = require('path').join;
var cp = require('child_process');
/**
* Migrate a file to TypeScript.
*
* @example
* // will rename file and try to infer types
* yarn ts:migrate ./src/utils.js
*
@julioxavierr
julioxavierr / scan.spec.ts
Created April 16, 2021 12:50
Mock event callback
import { scan } from '../scan';
import { BleManager, Device } from 'react-native-ble-plx';
import {
BleErrorCodeMessage,
BleError,
} from 'react-native-ble-plx/src/BleError';
let cb: Parameters<BleManager['startDeviceScan']>[2] = null;
jest.mock('react-native-ble-plx', () => ({
BleManager: () => ({
startDeviceScan: jest.fn(((_, __, receivedCb) => {
@julioxavierr
julioxavierr / useInternetReachable.js
Last active November 23, 2020 18:53
Alternative hook to check if the internet is reachable with @react-native-community/netinfo that does not return false on the initial results
import { useState, useEffect } from 'react';
import NetInfo from '@react-native-community/netinfo';
const useInternetReachable = () => {
const [isReachable, setIsReachable] = useState(false);
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
const unsubscribe = NetInfo.addEventListener(({ isInternetReachable }) => {
if (typeof isInternetReachable !== 'boolean') return;
@julioxavierr
julioxavierr / useExpoResources.js
Last active February 27, 2020 13:03
React hook to abstract loading resources from expo and showing splash screen until completion
import { useEffect, useState } from 'react';
import * as Font from 'expo-font';
import { SplashScreen } from 'expo';
/**
* Load and use resources that need to be loaded async by Expo SDK
*/
const useExpoResources = () => {
const [isLoading, setIsLoading] = useState(true);
@julioxavierr
julioxavierr / inline-svg.sh
Last active January 9, 2020 19:43
Convert svg to use inline styles with one line
svgo path/to/file.svg --enable=inlineStyles --config '{ "plugins": [ { "inlineStyles": { "onlyMatchedOnce": false } }] }' --pretty
@julioxavierr
julioxavierr / useDebounce.ts
Created December 11, 2019 12:22
useDebounce hook with TS + underscorejs
import { useState, useEffect } from 'react';
import _ from 'underscore';
const DEFAULT_DEBOUNCE_TIMEOUT = 1000;
/**
* Debounce fast changing value.
* The debounced value will only reflect the latest value when the hook has not been called for the specified time period.
*/
function useDebounce(
@julioxavierr
julioxavierr / react-native-update.md
Last active July 23, 2019 01:46
Steps to update a React Native app

React Native Upgrade path

  • Change React and React Native version on package.json
  • run yarn install to upgrade dependencies
  • run yarn outdated or yarn upgrade-interactive libraries that are outdated (make sure that there's no breaking changes, check release notes (one by one))
  • check the diff or use the upgrade-helper and update the native code
  • open Xcode and link the binaries
  • run on iOS
  • test iOS
  • run on Android
  • test Android
import pyedflib
import numpy as np
import sys
from shutil import copyfile
import datetime
# copy input as output
copyfile(sys.argv[1], sys.argv[2])
# read input and get number of signals
@julioxavierr
julioxavierr / closestPoint.js
Created March 30, 2019 13:46
Find closest point in a Array
// num - number you're looking for
// pointArr - your array of points
// coordIdx - index of the coordinate you're searching for in the point
const closestPoint = (num, pointArr, coordIdx) => {
let mid;
let left = 0;
let right = pointArr.length - 1;
while (right - left > 1) {
mid = Math.floor((left + right) / 2);
if (pointArr[mid][coordIdx] < num) {
@julioxavierr
julioxavierr / tslint.json
Created February 13, 2019 19:25
TSLint rules
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"jsRules": {},
"rules": {
"no-shadowed-variable": false,
"interface-over-type-literal": false,
"member-access": false,