Skip to content

Instantly share code, notes, and snippets.

View skellock's full-sized avatar

Steve Kellock skellock

View GitHub Profile
@capaj
capaj / component.js
Last active June 22, 2016 12:40
react stateful function component
import React from 'react'
import {observer} from 'mobx-react'
import {observable} from 'mobx'
const state = observable({
value: 0
})
const Comp = (props) => {
return <div onClick={() => state.value++}>click to increase counter value: {state.value}</div>
@littlepsylo
littlepsylo / index.js
Last active July 28, 2016 13:37
Using WebSocket in react-native with a socket.io server
const io = new WebSocket('ws://yourdomain:port/socket.io/?transport=websocket')
io.onclose = e => console.log('onclose', e.code, e.reason)
io.onerror = e => console.log('onerror', e.message)
io.onopen = () => console.log('connected !')
@mmazzarolo
mmazzarolo / redux_naming_example.js
Created September 6, 2016 21:44
Redux naming example
import { find, findIndex, pullAt } from 'lodash'
import { actionTypes as appActionTypes } from 'reducers/appReducer'
export const actionTypes = {
CREATE_MENU_ENTRY_REQUEST: 'MENU/CREATE_MENU_ENTRY_REQUEST',
CREATE_MENU_ENTRY_SUCCESS: 'MENU/CREATE_MENU_ENTRY_SUCCESS',
CREATE_MENU_ENTRY_FAILURE: 'MENU/CREATE_MENU_ENTRY_FAILURE',
UPDATE_MENU_ENTRY_REQUEST: 'MENU/UPDATE_MENU_ENTRY_REQUEST',
UPDATE_MENU_ENTRY_SUCCESS: 'MENU/UPDATE_MENU_ENTRY_SUCCESS',
UPDATE_MENU_ENTRY_FAILURE: 'MENU/UPDATE_MENU_ENTRY_FAILURE',
@yelouafi
yelouafi / Counter.jsx
Last active October 5, 2016 07:13
redux-saga with vanilla React
import React, { Component } from 'react'
import { runSaga, delay } from 'redux-saga'
import { take, put, call } from 'redux-saga/effects'
// helper functions
const bindFunc = (comp, method) => (...args) => method.apply(comp, args)
const bindSaga = (comp, method) => (...args) => runSaga(method.apply(comp, args), {})
export default class Counter extends React.Component {
@sibelius
sibelius / Codemod RN24 to RN25.md
Last active November 9, 2016 13:09
Codemod React Native 24 imports to RN25 imports

README

Why this transform is necessary?

Until React Native 24, you import React from 'react-native' package, but this will change on RN 25, you will need to import React from 'react'. You probably have many files that does this, so I've created a codemod to save you a bunch of time

How to use this

  • Install jscodeshif
@adamreisnz
adamreisnz / Setup GitHub issue labels script
Last active November 17, 2016 14:38 — forked from hubertursua/setup github issues labels.sh
A terminal script to setup GitHub issue labels for a project.
Setup GitHub issue labels script
@sibelius
sibelius / android25.sh
Created May 16, 2017 12:03
Upgrade all node_modules dependencies do android 25
#!/usr/bin/env bash
find node_modules -name 'build.gradle' -print -exec sed -i.bak -E 's/compileSdkVersion[[:space:]]+23/compileSdkVersion 25/g' {} \;
find node_modules -name 'build.gradle' -print -exec sed -i.bak -E 's/buildToolsVersion[[:space:]]+"23.0.1"/buildToolsVersion "25.0.1"/g' {} \;
@joshjhargreaves
joshjhargreaves / LazyLoadComponent.js
Last active July 27, 2018 16:03
Use lazy requires for screens for React Navigation
//Navigator
const SettingsScreen = createLazyComponent(
() => require('../containers/component').default
);
// ...
const MainStackNavigator = StackNavigator(
{
SettingsScreen: {
screen: SettingsScreen,
@mjackson
mjackson / resolvePromise.js
Last active September 9, 2018 08:23
An easy way to do async APIs in JavaScript that support both promises *and* callbacks!
// Here is a function that I use all the time when creating public
// async APIs in JavaScript:
const resolvePromise = (promise, callback) => {
if (callback)
promise.then(value => callback(null, value), callback)
return promise
}
// Sometimes I like to use callbacks, but other times a promise is
@ebababi
ebababi / Dockerfile
Created November 10, 2019 20:17
Ruby on Rails Deployment Image: Builds a ready to be deployed image of a Ruby on Rails application.
# Ruby on Rails Deployment Image
#
# Builds a ready to be deployed image of a Ruby on Rails application.
# https://ebababi.net/dockerfile-for-ruby-on-rails-deployments.html
# Copyright (C) 2019 Nikolaos Anastopoulos, Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met: