// requires access to the activity
val sharedPreferencesFile = activity?.get()?.let {
it.getSharedPreferences("${it.packageName}_preferences", Context.MODE_PRIVATE)
This file contains hidden or 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
const padArrayEnd = <T>(arr: T[], targetLength: number, val: T): T[] => { | |
if (arr.length >= targetLength) return [...arr] | |
return arr.concat(Array(targetLength - arr.length).fill(val)) | |
} | |
console.log(padArrayEnd(["0", "1"], 3, "")) | |
console.log(padArrayEnd(["0", "1", "2"], 3, "")) | |
console.log(padArrayEnd(["0", "1", "2", "3"], 3, "")) |
What helped me to get everything running on my Apple Macbook with the M1 chip:
- Check first that your terminal is running on the
arm64
-architecture by runninguname -m
. If it’sx86_64
, you’re running on Rosetta (see https://earthly.dev/blog/using-apple-silicon-m1-as-a-cloud-engineer-two-months-in/) - Follow the normal environment setup guide from React Native
- Follow this answer from Stackoverflow when installing Cocoapods
- Run
pod install
in your iOS-folder, everything should be working flawless :)
This file contains hidden or 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 { combineReducers, Action } from '@reduxjs/toolkit'; | |
const withClearStateOnAction = <S = any>(clearStateAction: Action) => ( | |
reducer: Reducer<S | undefined, Action>, | |
) => (state: S, action: Action) => { | |
if (clearStateAction.type === action.type) { | |
return reducer(undefined, clearStateAction); | |
} | |
return reducer(state, action); | |
}; |
Density | Android density qualifier | iOS scaling factor |
---|---|---|
Low-density (~120dpi) | ldpi | not supported |
Medium-density (~160dpi) | mdpi | original scale |
High-density (~240dpi) | hdpi | not supported |
Extra-high-density (~320dpi) | xhdpi | @2x |
Extra-extra-high-density (~480dpi) | xxhdpi | @3x |
Extra-extra-extra-high-density (~640dpi) | xxxhdpi | @4x |
source: https://developer.android.com/studio/write/resource-manager#automatic-parsing
This file contains hidden or 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
/** | |
* Curried higher-order function taking a predicate and an actual resolver function. In case the | |
* predicate returns true, an empty list is returned, otherwise the result of the actual resolver function. | |
* | |
* Both the predicate and the resolver function will get the all arguments as a standard resolver function. | |
*/ | |
const condResolveEmptyList = predicate => resolver => ( | |
data, | |
args, | |
context, |
This file contains hidden or 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
const { performance } = require('perf_hooks'); | |
const express = require('express'); | |
const expressRequestDurationMiddleware = (req, res, next) => { | |
performance.mark('request.start'); | |
const end = res.end; | |
res.end = (...args) => { | |
performance.mark('request.end'); |
NewerOlder