Skip to content

Instantly share code, notes, and snippets.

View ourmaninamsterdam's full-sized avatar

Justin Perry ourmaninamsterdam

View GitHub Profile
@ourmaninamsterdam
ourmaninamsterdam / LICENSE
Last active April 24, 2024 18:56
Arrayzing - The JavaScript array cheatsheet
The MIT License (MIT)
Copyright (c) 2015 Justin Perry
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
(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))
(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 / mqtt-event-channel.ts
Last active November 30, 2023 12:49
WIP redux-saga/MQTT event channel
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) {
@ourmaninamsterdam
ourmaninamsterdam / taskSagas.ts
Last active November 16, 2023 20:42
redux-saga - Running long tasks then cancelling
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");
@ourmaninamsterdam
ourmaninamsterdam / promise-logic.ts
Last active April 17, 2023 10:06
Promise business/runtime logic error handling
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]
}
// index.js
require('./a');
require('./b');
// mqtt.js
class MQTT {
connect() {
const connectionId = Math.random();
console.log('connected to: ', connectionId);
this.connectionId = connectionId;
@ourmaninamsterdam
ourmaninamsterdam / simple-pagination.html
Created January 24, 2013 18:50
Simple JS pagination script that can be easily modified to accept a JSON array. Known bug where pages 11-20 are skipped when paging through.
<!DOCTYPE html>
<html lang="en-GB">
<head>
<title>Simple JavaScript pagination</title>
<meta charset="UTF-8">
<style>
div{
position: relative;
}
#stage{
@ourmaninamsterdam
ourmaninamsterdam / expo-notifications+0.13.3.patch
Last active June 28, 2022 08:22
expo-notifications: Patch to resolve "Error: Failed to schedule notification" issue on Expo SDK 43 with SDK version 31
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 / arrayzing.md
Last active June 8, 2022 23:49
Array Cheatsheet

Array Cheatsheet

Creating an array

var meals = ['breakfast', 'lunch', 'dinner'] ;

Or