Skip to content

Instantly share code, notes, and snippets.

Avatar

Justin Perry ourmaninamsterdam

View GitHub Profile
@ourmaninamsterdam
ourmaninamsterdam / expo-notifications+0.13.3.patch
Last active Jun 28, 2022
expo-notifications: Patch to resolve "Error: Failed to schedule notification" issue on Expo SDK 43 with SDK version 31
View expo-notifications+0.13.3.patch
diff --git a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/service/NotificationsService.kt b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/service/NotificationsService.kt
index 8e675c4..2062951 100644
--- a/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/service/NotificationsService.kt
+++ b/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/service/NotificationsService.kt
@@ -8,6 +8,7 @@ import android.content.Intent
import android.content.pm.ActivityInfo
import android.net.Uri
import android.os.Bundle
+import android.os.Build
import android.os.Parcel
@ourmaninamsterdam
ourmaninamsterdam / retryAsync.spec.ts
Created Apr 6, 2022
retryAsync - retry an async function a set amount of times
View retryAsync.spec.ts
import retryAsync from '~utils/retryAsync';
describe('retryAsync', () => {
describe('with retry attempts left', () => {
describe('if the async function promise rejects', () => {
it('retries the given async function 3 times before eventually throwing', async () => {
const mockAsyncFn = jest.fn().mockRejectedValue('failed');
await expect(retryAsync(3, () => mockAsyncFn())).rejects.toThrow();
expect(mockAsyncFn).toHaveBeenCalledTimes(3);
@ourmaninamsterdam
ourmaninamsterdam / method-overloading.ts
Last active Feb 12, 2022
Method overloading in TypeScript
View method-overloading.ts
// Adapted from https://howtodoinjava.com/typescript/function-overloading
class MiddleEarthResident {
name: string;
constructor(name: string) {
this.name = name;
}
}
class ShireResident extends MiddleEarthResident {
@ourmaninamsterdam
ourmaninamsterdam / Person.java
Created Jul 17, 2021
Java - hierarchy relationship in an enum
View Person.java
// From https://stackoverflow.com/questions/44654291/is-it-good-practice-to-use-ordinal-of-enum
public enum Person {
GRANDPARENT(null),
PARENT(GRANDPARENT),
CHILD(PARENT);
private final Person parent;
private Person(Person parent) {
@ourmaninamsterdam
ourmaninamsterdam / useDirectorySync.ts
Created Jun 23, 2021
useDirectorySync - syncs React Native directories (using react-native-fs) on appState change
View useDirectorySync.ts
import { useState } from 'react';
import useAppState from 'react-native-appstate-hook';
import RNFS from 'react-native-fs';
async function copyDir(source: string, destination: string) {
const fileChangeLog: string[] = [];
await copyDirRecursive(source, destination, fileChangeLog);
return fileChangeLog;
@ourmaninamsterdam
ourmaninamsterdam / abstract.md
Last active Jan 16, 2021
Abstract list operations and signatures - racket-lang
View abstract.md

Natural -> (listof X) - build-list

(listof X) -> (listof X) - filter

(listof X) -> (listof Y) - map

(listof X) -> Boolean - andmap

(listof X) -> Boolean - ormap

View fold-fn.rkt
(define (find name dir)
(local [(define (c1 n rdirs rimgs)
(or (string=? name n)
rdirs
rimgs))
(define (c2 rdir rdirs)
(or rdir rdirs))
(define (c3 img rimgs)
false)]
(fold-dir c1 c2 c3 false false dir)))
View has-path.rkt
(define-struct node (k v l r))
;; BinaryTree is one of:
;; - false
;; - (make-node Natural String BinaryTree BinaryTree)
(define BT0 false)
(define BT1 (make-node 1 "a" false false))
(define BT4 (make-node 4 "d"
(make-node 2 "b"
(make-node 1 "a" false false)
(make-node 3 "c" false false))
@ourmaninamsterdam
ourmaninamsterdam / sumAllKeys.ts
Last active Oct 10, 2020
Sum all keys from a BST
View sumAllKeys.ts
type BST = {
key: number;
value: string;
left: BST | false;
right: BST | false;
} | false;
const BST0: BST = false;
const BST1: BST = {
key: 1,
@ourmaninamsterdam
ourmaninamsterdam / useLocationProviderStatus.ts
Last active Oct 10, 2020
Reports LocationProviderStatus (GPS/network or passive location Android only) from expo-location
View useLocationProviderStatus.ts
import { getProviderStatusAsync, LocationProviderStatus } from 'expo-location';
import { useState } from 'react';
import { Platform } from 'react-native';
import useInterval from 'use-interval';
const useLocationProviderStatus = (delay: number = 2000) => {
const [locationProviderAvailable, setLocationProviderAvailable] = useState<boolean | undefined>(undefined);
const getLocationProviderStatus = ({
gpsAvailable,