Skip to content

Instantly share code, notes, and snippets.

View robinheinze's full-sized avatar

Robin Heinze robinheinze

View GitHub Profile
def numbers_to_words(number, index = 0)
ones_words = {1 => "one", 2 => "two", 3 => "three", 4 => "four", 5 => "five", 6 => "six", 7 => "seven", 8 => "eight", 9 => "nine", 10 => "ten", 11 => "eleven", 12 => "twelve", 13 => "thirteen", 14 => "fourteen", 15 => "fifteen", 16 => "sixteen", 70 => "seventeen", 18 => "eighteen", 19 => "nineteen", 0 => "\b"}
decades = {0 => "\b", 20 => "twenty", 30 => "thirty", 40 => "forty", 50 => "fifty", 60 => "sixty", 70 => "seventy", 80 => "eighty", 90 => "ninety"}
magnitudes = ["", "thousand", "million", "billion", "trillion"]
result = []
if number > 999
result << numbers_to_words(number / 1000, index + 1) << numbers_to_words(number % 1000, index)
elsif number > 99
result << numbers_to_words(number / 100) << "hundred" << numbers_to_words(number % 100) << magnitudes[index]
@robinheinze
robinheinze / multi-column-section-list-example.md
Last active March 14, 2024 15:09
Multi-column SectionList using FlatList

First, let's assemble the data. Say we have two sets of objects: Fruits and Vegetables.

const fruits = [
  {
    name: 'Apple',
    color: 'Green'
  },
  {
    name: 'Banana',
@robinheinze
robinheinze / Dimensions.jsx
Created June 12, 2019 21:08
Using react-native Dimensions API dynamically
import * as React from "react"
import { View, Dimensions } from 'react-native'
const STYLE = {
width: Dimensions.get("window").width,
height: Dimensions.get("window").height,
backgroundColor: "yellow"
}
export class MyComponent extends React.Component {
@robinheinze
robinheinze / question.ts
Last active April 7, 2021 21:13
Question
export const QuestionModel = types
.model("Question")
.props({
id: types.identifier,
category: types.maybe(types.string),
type: types.enumeration(["multiple", "boolean"]),
difficulty: types.enumeration(["easy", "medium", "hard"]),
question: types.maybe(types.string),
correctAnswer: types.maybe(types.string),
incorrectAnswers: types.optional(types.array(types.string), []),
@robinheinze
robinheinze / api-config.ts
Last active April 7, 2021 21:15
API (Ice and Fire)
export const DEFAULT_API_CONFIG: ApiConfig = {
url: env.API || "https://opentdb.com/api.php",
timeout: 10000,
}
@robinheinze
robinheinze / question-store.ts
Last active July 22, 2019 20:31
Question Store with extension
export const QuestionStoreModel = types
.model("QuestionStore")
.props({
questions: types.optional(types.array(QuestionModel), []),
})
.extend(withEnvironment)
.views(self => ({})) // eslint-disable-line @typescript-eslint/no-unused-vars
.actions(self => ({})) // eslint-disable-line @typescript-eslint/no-unused-vars
@robinheinze
robinheinze / question-store.ts
Created July 22, 2019 21:23
Question Store Action
export const QuestionStoreModel = types
.model("QuestionStore")
.props({
questions: types.optional(types.array(QuestionModel), []),
})
.extend(withEnvironment)
.views(self => ({})) // eslint-disable-line @typescript-eslint/no-unused-vars
.actions(self => ({
saveQuestions: (questionSnapshots: QuestionSnapshot[]) => {
const questionModels: Question[] = questionSnapshots.map(c => QuestionModel.create(c)) // create model instances from the plain objects
@robinheinze
robinheinze / main-navigator.ts
Last active April 9, 2021 18:07
IgniteTrivia primary navigator
import { createStackNavigator } from "@react-navigation/stack"
import { QuestionScreen } from "../screens"
/**
* This type allows TypeScript to know what routes are defined in this navigator
* as well as what properties (if any) they might take when navigating to them.
*
* If no params are allowed, pass through `undefined`. Generally speaking, we
* recommend using your MobX-State-Tree store(s) to keep application state
* rather than passing state through navigation params.
@robinheinze
robinheinze / question-screen.tsx
Last active April 8, 2021 17:25
IgniteTrivia Question Screen initial
import React from "react"
import { observer } from "mobx-react-lite"
import { View, ViewStyle } from "react-native"
import { Screen, Text } from "../../components"
// import { useNavigation } from "@react-navigation/native"
// import { useStores } from "../../models"
import { color, spacing } from "../../theme"
const ROOT: ViewStyle = {
flex: 1,
@robinheinze
robinheinze / question-screen.tsx
Last active April 8, 2021 16:45
IgniteTrivia Question Screen injected store
import { useStores } from "../../models"
...
export const QuestionScreen = observer(function QuestionScreen() {
// Pull in one of our MST stores
const { questionStore } = useStores()
...