Skip to content

Instantly share code, notes, and snippets.

View parkerproject's full-sized avatar

Parker parkerproject

View GitHub Profile
@parkerproject
parkerproject / index.js
Created September 23, 2016 05:45 — forked from waltcow/index.js
Example with react-native-gifted-listview and redux implementation
import React, {Component, PropTypes} from "react";
import {View, ListView, Text, NetInfo, TouchableHighlight, Image} from "react-native";
import Icon from 'react-native-vector-icons/Ionicons'
import GiftedListView from 'react-native-gifted-listview'
import GiftedSpinner from 'react-native-gifted-spinner'
import Animatable from 'react-native-animatable'
import Swipeout from 'react-native-swipeout'
@parkerproject
parkerproject / 1-react-native-simulator-and-device.md
Created September 30, 2016 17:26 — forked from almost/1-react-native-simulator-and-device.md
Test React Native on the simulator and on a device without editing the code each time!

In the default React Native app scaffolding you have to edit AppDelegate.m to change where it loads the code if you want to test on your device. I use the following snippet to detect if it's being compiled for Debug or Production and for the Simulator or a device. For Production it uses a copy of the code included in the bundle, for Debug on the simualtor it loads from a server on localhost and for Debug on a device it loads from a server on a given IP address.

NOTE: You need to edit YOUR-IP-HERE and change it to the IP to load the code from when in Debug mode on a device. You could use a service like ngrok to make this work from anywhere.

  NSURL *jsCodeLocation;

  // Loading JavaScript code
  #if DEBUG
    // For Debug build load from development server. Start the server from the repository root:
@parkerproject
parkerproject / gist:6a55c56b52571026478710abfb08c1cb
Created December 2, 2016 19:40
Simple node.js code style tips to improve code quality

Whether you use 2 spaces or 4 spaces, there are a few simple things that can make your node.js code easier to read. We've been using them in all the hapi modules for over 4 years now to great results. This list is by no means complete but it highlights the most useful elements that will give you immediate value in reducing bugs.

Required modules

JavaScript makes it harder than most languages to know where variables are coming from. Variables assigned required modules are particularly important because they represent a singleton object shared with the entire application. There are also globals and module globals, along with function variables and arguments.

Traditionally, variables starting with an uppercase letter represent a class that must be instantiated using new. This was an important semantic in the early days of JavaScript but at this point, if you don't know Date requires new Date() you are probably very new. We have adopted Upper Camel Case variable names for all module global variables

@parkerproject
parkerproject / proxy.js
Created December 8, 2016 20:43 — forked from gouroujo/proxy.js
Proxy on /api for express app using node http-proxy
import { createProxyServer } from 'http-proxy';
import url from 'url';
import _ from 'lodash';
module.exports = app => {
const proxy = createProxyServer();
app.all('/api/v1/*', (req, res) => {
const path = _.drop(req.url.split('/'), 3);
proxy.proxyRequest(req, res, {
target: url.resolve('YOUR URL', path.join('/')),
@parkerproject
parkerproject / tabs.js
Created December 20, 2016 17:47 — forked from hong6/tabs.js
<style>
.wrapper {width: 600px; margin: 20px auto; }
ul.tabs {float: left; width: 200px; }
</style>
<div class="wrapper">
<ul class="tabs">
<li><a href="#gallery">Gallery</a></li>
<li><a href="#submit">Submit</a></li>
@parkerproject
parkerproject / .eslintrc
Created December 31, 2016 21:37 — forked from gilbarbara/.eslintrc
.eslintrc configuration file for ES2015 + react
{
"parser": "babel-eslint",
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true
},
"env": {
"amd": true,
"browser": true,
"es6": true,
@parkerproject
parkerproject / Enhance.js
Created January 10, 2017 04:22 — forked from sebmarkbage/Enhance.js
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
// @flow
import React, { Component } from 'react'
import { Image, Animated, View } from 'react-native'
type ProgressiveImageState = {
thumbnailOpacity: number,
key: string
}
@parkerproject
parkerproject / post-merge
Created January 26, 2017 17:50 — forked from sindresorhus/post-merge
git hook to run a command after `git pull` if a specified file was changed.In this example it's used to run `npm install` if package.json changed and `bower install` if `bower.json` changed.Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
#!/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"