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
| interface Metric { | |
| timestamp: Date; | |
| temperature: number; | |
| pressure: number; | |
| humidity: number; | |
| rain: number; | |
| sun: number; | |
| windDirection: number; | |
| windVelocity: number; | |
| dew: number; |
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
| /* SelectedPick<T, Selector> | |
| An extended version of Pick<T, Key> where, instead of a union of keys, | |
| you pass an object with the properties to get from a type. */ | |
| type Extends<T1, T2> = [T1] extends [T2] ? true : false | |
| type OmitNever<T> = Pick<T, { [K in keyof T]: T[K] extends never ? never : K }[keyof T]> | |
| export type Selector<Model> = { | |
| [Key in keyof Model]?: boolean | NestedSelectorValue<Model[Key]> |
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 React from "react"; | |
| import PropTypes from "prop-types"; | |
| import { Text, View, StyleSheet } from "react-native"; | |
| import { Camera, Permissions } from "expo"; | |
| /* Expo does not provide a light component, but we can control the flash using the Camera component. */ | |
| class FlashLight extends React.Component { | |
| static propTypes = { | |
| isActive: PropTypes.bool.isRequired | |
| }; |
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
| /* Stateful component wrapper over wavesoft/dot-dom with a functional reducer (hooks supported) */ | |
| function mapValues(input, mapper) { | |
| return Object.keys(input).reduce((acc, key) => { | |
| const value = mapper(input[key], key); | |
| return value ? Object.assign(acc, { [key]: value }) : acc; | |
| }, {}); | |
| } | |
| function _setState(setState, newState$) { |
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
| /* Some monadic and helper functions */ | |
| function* pure<T>(value: T): IterableIterator<T> { | |
| yield value; | |
| } | |
| function* concat<T>(...iterators: Array<IterableIterator<T>>): IterableIterator<T> { | |
| for (const iterator of iterators) { | |
| yield* iterator; | |
| } |
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
| #!/bin/sh | |
| exec dbus-send \ | |
| --session \ | |
| --dest=org.xfce.SessionManager \ | |
| --print-reply /org/xfce/SessionManager \ | |
| org.xfce.Session.Manager.Checkpoint string:"" |
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
| #!/usr/bin/env node | |
| /* | |
| * @fileoverview Program to free the content in kindle books as plain HTML. | |
| * | |
| * This is largely based on reverse engineering kindle cloud app | |
| * (https://read.amazon.com) to read book data from webSQL. | |
| * | |
| * Access to kindle library is required to download this book. | |
| */ |
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
| async function(request, response, next) { | |
| return validate() | |
| .then(() => { | |
| return doRealWork() | |
| .then(result => response.send(result)) | |
| .catch(error => next(error))) | |
| }) | |
| .catch(error => response.status(400).send(error)) | |
| } |
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
| // intersperse(items: any[], value: any): any[] | |
| // http://hackage.haskell.org/package/base-4.12.0.0/docs/Data-List.html#v:intersperse | |
| const _ = require('lodash'); | |
| _.mixin({ | |
| intersperse(array, sep) { | |
| return _(array) | |
| .flatMap(x => [x, sep]) | |
| .slice(0, -1) |
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
| module StringMap = Map.Make({ type t = string; let compare = compare; }); | |
| let mapFromList = (pairs: list((string, 'a))): StringMap.t('a) => | |
| List.fold_left((map, (k, v)) => StringMap.add(k, v, map), StringMap.empty, pairs); | |
| let mapGet = (key: string, defaultValue: 'a, mapping: StringMap.t('a)): 'a => | |
| switch (StringMap.find(key, mapping)) { | |
| | exception Not_found => defaultValue | |
| | value => value | |
| }; |