Calculate the height of the keyboard when it is open.
An apollo useQuery
hook with built-in support for ScrollView's RefreshControl
/** | |
* Polyfill - Array.prototype.findIndex | |
* | |
* https://tc39.github.io/ecma262/#sec-array.prototype.findIndex | |
*/ | |
if (!Array.prototype.findIndex) { | |
Object.defineProperty(Array.prototype, 'findIndex', { | |
value: function(predicate) { | |
// 1. Let O be ? ToObject(this value). | |
if (this == null) { |
/** | |
* A simple app store utilizing localStorage. | |
*/ | |
/** | |
* Initialize the store. | |
*/ | |
application = application || {}; | |
application.store = {}; |
'use strict'; | |
/** | |
* Benchmark the sh#t out of stuff | |
* Use this in NodeJS environments. | |
* Shamelessly borrowed from: https://www.stefanjudis.com/today-i-learned/measuring-execution-time-more-precisely-in-the-browser-and-node-js/ | |
* | |
* USAGE: | |
* `const benchmark = Benchmark(); // starts the 'clock'` | |
* `benchmark(); // logs current elapsed ns since start or last benchmark` |
import { Component } from 'react'; | |
/** | |
* Auto-bind all methods of a React class, excluding lifecycle methods | |
* | |
* USAGE: | |
* | |
* ``` | |
* class MyClass extends ComponentAutoBind { ... } | |
* ``` |
const delay = (callback, time = 5000) => { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve(); | |
}, time); | |
}) | |
.then(callback); | |
} | |
// USAGE |
# | |
# Simulates a shuffled deck of cards. | |
# This demonstrates *one* way to simulate drawing | |
# 5 cards at a time from a deck of cards. | |
# This logic could easily be applied to games such | |
# as Blackjack or Texas Hold'em. | |
# | |
# Note - I included a card.val method specifically for | |
# checking a card's value for comparison in Poker (e.g. | |
# a straight is 5 consecutive card vals of the same suite). |
const badwords = [ | |
'frick', | |
'fark', | |
'dern', | |
'shiz' | |
].join('|'); | |
const badEmojis = [ | |
'\\u{1F4A9}', // pile of poo | |
'\\u{1F595}' // middle finger | |
].join('|'); |
# stolen from: http://blog.joncairns.com/2013/01/reset-postgresql-auto-increment-value-in-rails/ | |
TABLES_TO_IGNORE = [] | |
ActiveRecord::Base.connection.tables.each do |table| | |
next if TABLES_TO_IGNORE.include?(table) | |
result = ActiveRecord::Base.connection.execute("SELECT id FROM #{table} ORDER BY id DESC LIMIT 1") | |
if result.any? | |
ai_val = result.first['id'].to_i + 1 | |
puts "Resetting auto increment ID for #{table} to #{ai_val}" | |
ActiveRecord::Base.connection.execute("ALTER SEQUENCE #{table}_id_seq RESTART WITH #{ai_val}") | |
end |
#!/bin/bash | |
# ReactNative script to nuke all the things | |
# usage: | |
# - add each item below as a separate script in package.json | |
# - add one final script: | |
# - "nuke": "yarn clean-node-modules && yarn clean-pods && yarn clean-ios && yarn clean-android && yarn clean-rn-cache" | |
# - alternatively, copy this shell script and add the following cmd to package.json: | |
# - "nuke": "./react-native-nuke-sh" | |
# - you may need to run `sudo chmod 777 ./react-native-nuke-sh before this script can run` |