This file contains 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 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 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 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 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 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 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 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 | |
}; |
This file contains 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 puppeteer = require('puppeteer'); | |
const escapeXpathString = str => { | |
const splitedQuotes = str.replace(/'/g, `', "'", '`); | |
return `concat('${splitedQuotes}', '')`; | |
}; | |
const clickByText = async (page, text) => { | |
const escapedText = escapeXpathString(text); | |
const linkHandlers = await page.$x(`//a[contains(text(), ${escapedText})]`); |
This file contains 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
function escapeXpathString(str) { | |
const splitedQuotes = str.replace(/'/g, `', "'", '`); | |
return `concat('${splitedQuotes}', '')`; | |
} |