Skip to content

Instantly share code, notes, and snippets.

View Grohden's full-sized avatar
:shipit:
*tec tec tec noises*

Gabriel Rohden Grohden

:shipit:
*tec tec tec noises*
View GitHub Profile
@Grohden
Grohden / test.ts
Last active May 7, 2019 21:15
My try on dependent types + conditional types using typescript to validate optional args based on a key
type Routes = {
a: {
string: string
}
b: undefined
}
type NullableKeys<T, K extends keyof T> = T[K] extends null | undefined
? K
@Grohden
Grohden / make-revision-file.js
Created May 16, 2019 04:56
NodeJs script to read two specific files for translation and write them together for better revision
const fs = require('fs');
const english = require("./english.json").text
const portuguese = require("./portuguese.json").text
const DEFAULT_KEY = "en-US"
const accumlator = {}
// Acc the english ones
english.reduce((all, value) => {
all[value.key] = {
@Grohden
Grohden / App.js
Last active May 22, 2019 13:15
React navigation + react hooks problem with callback param
import React from 'react';
import {
createAppContainer,
createStackNavigator
} from 'react-navigation'
import TestScreen, {
testScreenOptions
} from './TestScreen'
const stack = createStackNavigator({
@Grohden
Grohden / AutoHeightRBSheet.tsx
Last active January 9, 2023 09:56
React native raw bottom sheet with auto height calcs
// This is basically a copy of
// https://github.com/nysamnang/react-native-raw-bottom-sheet
// but using only translate animations instead of height
import React, {
forwardRef, ReactNode,
RefForwardingComponent,
useImperativeHandle,
useState
} from 'react'
@Grohden
Grohden / Lightbox.tsx
Created June 24, 2019 18:17
Just saving this refactor of the lightbox
import React, {
Children,
cloneElement, FC, useRef, useState
} from 'react'
import {
Animated,
TouchableHighlight,
View,
ViewStyle
} from 'react-native'
@Grohden
Grohden / example-json-model.json
Last active June 28, 2019 15:29
Generate dart deserialization and model classes based on JSON input
{
"pageCount": 1,
"result": [
{
"page_number": 12,
"is_favorite": true,
"cover": {
"width": 40,
"height": 50,
"url": "www.test.com"
@Grohden
Grohden / deep-typename-apollo.ts
Created August 9, 2019 03:06
Fn to put deep __typename based on keys for apollo gql (apollo link rest is too verbose)
/*
* This is micro optimized, you could
* do it without mutability, but I think
* that this is to solve a very specific case (apollo
* requires __typename to be injected)
*/
function addTypeNames(
item: object,
typeNames: object
) {
@Grohden
Grohden / pick-keys-by-type.ts
Created August 9, 2019 03:58
Utility type to pick keys by type
export type Primitive = string | number | boolean | bigint | symbol | undefined | null;
export type PickKeysDeep<T, P = any> = {
[K in keyof T]: T[K] extends object
? P extends Primitive
? PickKeysDeep<T[K], P>
: K | PickKeysDeep<T[K], P>
: P extends Primitive
? P extends T[K]
? K
@Grohden
Grohden / convert-taps.js
Last active September 23, 2019 03:46
After reading the android monkey sources, i came up with this: a way to make a monkey runner "script" by hand
// Let's suppose you have this in adb:
const adbCommands = `input tap 450 450
input tap 740 280
input tap 683 614
input tap 950 411
input tap 1188 248
input tap 915 713
input tap 1176 560
input tap 1428 358
input tap 1149 789
@Grohden
Grohden / BottomNavigator.ts
Last active September 26, 2019 18:33
Solution for react-navigation/stack/issues/237 (stack header animation is buggy on android P due to elevation animations)
import {
BottomRoutes,
NavigationDefinitionMap,
TNavigatorOptions
} from '../../lib/navigation'
import {
createBottomTabNavigator
} from 'react-navigation-tabs'
import RequestListScreen, {
requestListNavigatorOptions