Skip to content

Instantly share code, notes, and snippets.

View cooperka's full-sized avatar

Kevin Cooper cooperka

View GitHub Profile
@cooperka
cooperka / output.txt
Created September 21, 2016 18:09
jest --debug
> JestBrokenPromises@0.0.1 test /Users/klap-hotel/Dev/JestBrokenPromises
> jest "--debug"
jest version = 15.1.1
test framework = jasmine2
config = {
"haste": {
"defaultPlatform": "ios",
"platforms": [
"android",
@cooperka
cooperka / ListView to ImmutableListView.diff
Last active August 1, 2017 04:40
Migrating from ListView to ImmutableListView in React Native.
-import { Text, View, ListView } from 'react-native';
+import { Text, View } from 'react-native';
+import { ImmutableListView } from 'react-native-immutable-list-view';
import style from './styles';
import listData from './listData';
class App extends Component {
- constructor(props) {
@cooperka
cooperka / ListView to FlatList.diff
Last active June 18, 2020 05:36
Migrating from ListView to FlatList in React Native.
-import { Text, View, ListView } from 'react-native';
+import { Text, View, FlatList } from 'react-native';
import style from './styles';
import listData from './listData';
class App extends Component {
- constructor(props) {
- super(props);
@cooperka
cooperka / ImmutableListView to ImmutableVirtualizedList.diff
Last active August 1, 2017 04:39
Migrating from ImmutableListView to ImmutableVirtualizedList in React Native (similar to FlatList).
import { Text, View } from 'react-native';
-import { ImmutableListView } from 'react-native-immutable-list-view';
+import { ImmutableVirtualizedList } from 'react-native-immutable-list-view';
import style from './styles';
import listData from './listData';
class App extends Component {
- renderRow(rowData) {
@cooperka
cooperka / getFlatList.bash
Last active January 12, 2021 16:36
How to download FlatList and its related dependencies directly into your node_modules.
mkdir -p node_modules/react-native/Libraries/Lists/ && \
for file in 'FlatList' 'MetroListView' 'SectionList' 'VirtualizedList' 'VirtualizedSectionList' 'ViewabilityHelper' 'VirtualizeUtils'; \
do curl https://raw.githubusercontent.com/facebook/react-native/master/Libraries/Lists/${file}.js > node_modules/react-native/Libraries/Lists/${file}.js; \
done
@cooperka
cooperka / SyncManager.js
Last active December 9, 2018 17:59
This is why I love redux-saga + ES6 generators.
/**
* Root sagas can be exported from every file, and are all bundled together in one master saga.
* This saga listens for requests to sync, as well as failure events.
*/
export default function* rootSaga() {
yield fork(takeLatest, cacheManagerActionTypes.SYNC_ALL, startSync);
yield fork(takeLatest, cacheManagerActionTypes.SYNC_FAILED, showSyncFailed);
}
/**
@cooperka
cooperka / emoji-utils.js
Last active April 11, 2017 15:16
"Pure emoji string" detection
import emojiRegexCreator from 'emoji-regex';
const emojiRegex = emojiRegexCreator();
export default {
isPureEmojiString(text) {
if (!text || !text.trim()) return false;
return text.replace(emojiRegex, '').trim() === '';
@cooperka
cooperka / Expo error.html
Last active July 17, 2017 19:27
Expo error trying to run the react-navigation NavigationPlayground example app
<!doctype html5>
<html>
<head>
<style type="text/css">
strong { font-weight: bold; }
hr { -moz-box-sizing: content-box; box-sizing: content-box; height: 0; }
html { font-family: sans-serif; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; } body { margin: 0; }
a { background-color: transparent; }
a:active, a:hover { outline: 0; }
@cooperka
cooperka / Pull directly from PRs.sh
Created July 19, 2017 15:00
A one-time setup to fetch code directly from GitHub PRs, so you don't need to download their fork or figure out their branch name.
# One-time setup
git config --global --add remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git config --global --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*" # This is the important one
# Make sure there aren't duplicate configs
git config --global --list
# Checkout someone else's PR!
git fetch origin
git checkout pr/20
@cooperka
cooperka / React redux component structure.md
Last active May 2, 2019 23:28
How I personally organize my React components.
src/
  index.js                # Renders an <App /> component.
  reducers.index.js       # Exports a root Redux reducer (or MobX store).

  components/
    MyComponent/
      component.js        # Exports MyComponent.
      component.test.js   # Contains tests.
      actions.js          # Exports Redux "action type" strings and "action creator" functions.