Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<!--
Open this file in Safari
Open the developer tools
Refresh the page
Observe crash in "Anonymous Script" function "containsSchemaOrgMarkup"
-->
<script type="application/ld+json">
[]
</script>
import {
PlatformColor,
DynamicColorIOS as BaseDynamicColorIOS,
Platform
} from 'react-native'
// Stops this crashing when called on other platforms
const DynamicColorIOS = Platform.select({
ios: BaseDynamicColorIOS,
default: () => null
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background">#FFFFFF</color>
<color name="color">#212121</color>
</resources>
import { DynamicColorIOS } from 'react-native'
const styles = StyleSheet.create({
title: {
color: DynamicColorIOS({
light: 'black',
dark: 'white'
})
}
})
import { useColorScheme } from 'react-native'
const styles = StyleSheet.create({
titleLight: {
color: 'black'
},
titleDark: {
color: 'white'
}
})
type scalar = [ | `Fraction(int, int) | `Decimal(float)];
type value = [ scalar | `Vector(list(scalar)) | `nan];
let addScalar = (a, b) =>
switch (a, b) {
| (`Fraction(n1, d1), `Fraction(n2, d2)) =>
`Fraction((n1 * d2 + n2 * d1, d1 * d2))
| (`Fraction(n, d), `Decimal(f))
| (`Decimal(f), `Fraction(n, d)) =>
`Decimal(f *. float_of_int(n) /. float_of_int(d))
type scalar = [ | `Fraction(int, int) | `Decimal(float)];
type value = [ scalar | `Vector(list(scalar))];
let addScalar = (a, b) =>
switch (a, b) {
| (`Fraction(n1, d1), `Fraction(n2, d2)) =>
`Fraction((n1 * d2 + n2 * d1, d1 * d2))
| (`Fraction(n, d), `Decimal(f))
| (`Decimal(f), `Fraction(n, d)) =>
`Decimal(f *. float_of_int(n) /. float_of_int(d))
type length = [ | `Meter | `Inch];
type time = [ | `Second | `Minute | `Hour];
type temperatureLinear = [ | `Kelvin];
type temperatureNonLinear = [ | `Celsius];
type unitLinear = [ length | time | temperatureLinear];
type anyUnit = [ unitLinear | temperatureNonLinear];
let siScale = (unit: unitLinear) =>
switch (unit) {
type primary = [ | `Red | `Green | `Blue];
type colorFunctions = [ | `Rgb(int, int, int) | `Hsl(int, int, int)];
type colors = [ primary | colorFunctions];
let firstBracketPair = inputChars => {
let rec iter = (currentState, chars, currentIndex) =>
switch (currentState, chars) {
| (`FoundBracket(startIndex), [')', ..._]) =>
Some((startIndex, currentIndex))
| (_, ['(', ...tail]) =>
iter(`FoundBracket(currentIndex), tail, currentIndex + 1)
| (_, [_, ...tail]) =>
iter(currentState, tail, currentIndex + 1)
| (_, []) =>