Skip to content

Instantly share code, notes, and snippets.

View ahartzog's full-sized avatar
🏠
Working from home

Alek Hartzog ahartzog

🏠
Working from home
View GitHub Profile
@ahartzog
ahartzog / class-formidable-forms.php
Created November 1, 2021 11:41
Quick gist of extra line for Jack
/**
* Sync additional meta after user profile update
*
* @access public
* @return void
*/
public function after_update_user( $action, $entry, $form ) {
if (class_exists("FrmRegEntryHelper")) {
@ahartzog
ahartzog / timedClearCaches.ts
Created September 21, 2021 00:27
Weekly Cache Clearing Script for React Native
import FastImage from "react-native-fast-image";
import AsyncStorage from '@react-native-community/async-storage';
import moment from 'moment';
import ImagePicker from 'react-native-image-crop-picker';
import Sentry from 'modules/sentry';
const CACHE_TIME_KEY = 'cacheTimestamp'
const timedClearCaches = async () => {
@ahartzog
ahartzog / errorShapeFormatter.ts
Created September 16, 2021 16:38
With the new typescript strict setting for catch blocks error being "unknown", this utility function intakes that unknown and gives back a consistently usable Error.
const errorShapeFormatter = (thingToCatch: unknown) => {
if (thingToCatch instanceof Error) {
return thingToCatch as Error;
}
if (typeof thingToCatch === 'string') {
return new Error(thingToCatch);
}
if (
@ahartzog
ahartzog / FilesUploadingStore.ts
Created September 14, 2021 11:27
File uploading store example
import { observable, action, makeObservable } from 'mobx';
class FilesUIStore {
constructor() {
makeObservable(this, {
isUploading: observable,
uploadLoadProgress: observable,
isCompressing: observable,
dontShowProgress: observable,
setIsUploading: action,
/**
* @jest-environment jsdom
*/
import { renderHook } from '@testing-library/react-hooks';
import React from 'react';
import fetchMock from 'jest-fetch-mock';
import { mockAlekClient } from 'modules/mockdata';
import { Client } from 'modules/typescript';
import 'modules/config/src/globals';
@ahartzog
ahartzog / uploadMultipart.native.ts
Created June 2, 2021 18:58
Alek's Multipart Upload
import apiFetch from 'modules/api-fetch';
import Toast from 'modules/toast/index.native';
import Sentry from 'modules/sentry';
const FILE_CHUNK_SIZE = 5242880;
const uploadMultipart = async (
file: string,
setIsUploading = (set: boolean) => {},
setUploadProgress = (set: number) => {},
@ahartzog
ahartzog / detectNetworkConfig.ts
Created January 30, 2021 17:37
React Native Detect Network Status
// Example config from https://medium.com/@kulor/creating-an-offline-first-react-native-app-5534d7794969
import Config from 'modules/config';
import agent, { buildUrl } from 'modules/agent';
let online = true;
let timer = null as null | NodeJS.Timer;
const clearTimer = () => {
if (timer) {
@ahartzog
ahartzog / Podfile
Created October 22, 2019 12:35
Podfile
platform :ios, '10.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
require_relative '../node_modules/react-native-unimodules/cocoapods.rb'
target 'NFUMobileApp' do
# Pods for NFUMobileApp
pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
@ahartzog
ahartzog / AppDelegate.m
Created October 22, 2019 12:18
NFU AppDelegate.m
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "AppDelegate.h"
#import <CodePush/CodePush.h>
#import <React/RCTBridge.h>
@ahartzog
ahartzog / actionLogger.js
Created May 31, 2019 11:44
React Native AsyncStorage event logger
import moment from "moment";
import { sendSlackNotification } from "../../functions";
import AsyncStorage from "../../async-storage";
import purgeClientLogs from "./purgeClientLogs";
let currentlyWriting;
const awaitUntilDoneSubmitting = async () =>
new Promise(resolve => {
const timerCheckSubmitted = setInterval(() => {