This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function random(max: number) { | |
return Math.floor(Math.random() * max) | |
} | |
function* numberGenerator(limit: number) { | |
let current = 0; | |
let attempts = 0 | |
try { | |
while(current <= limit) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { eventChannel } from 'redux-saga'; | |
import { put, take } from 'redux-saga/effects'; | |
const createMqttChannel = mqtt => { | |
return eventChannel(emitter => { | |
const mqttMsgHandler = (payload: MqttMessage) => { | |
recorder.mqtt(payload); | |
const { event } = payload; | |
switch (event) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createStore, applyMiddleware } from "redux"; | |
import { all, fork, delay } from "typed-redux-saga"; | |
import createSagaMiddleware from "redux-saga"; | |
const sagaMiddleware = createSagaMiddleware(); | |
const store = createStore(() => undefined, applyMiddleware(sagaMiddleware)); | |
const task = sagaMiddleware.run(rootSaga); | |
function* taskSaga() { | |
console.log("taskSaga - start"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function findUser(id: number) { | |
console.log('Getting user...'); | |
await sleep(1000); | |
// Mocked out API | |
if(id === 999) { | |
return [new Error('User not found'), undefined] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// index.js | |
require('./a'); | |
require('./b'); | |
// mqtt.js | |
class MQTT { | |
connect() { | |
const connectionId = Math.random(); | |
console.log('connected to: ', connectionId); | |
this.connectionId = connectionId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adapted from https://howtodoinjava.com/typescript/function-overloading | |
class MiddleEarthResident { | |
name: string; | |
constructor(name: string) { | |
this.name = name; | |
} | |
} | |
class ShireResident extends MiddleEarthResident { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) { |
NewerOlder