Skip to content

Instantly share code, notes, and snippets.

View apehead's full-sized avatar
🐒
I'm going bananas!

Alexander Curiel apehead

🐒
I'm going bananas!
View GitHub Profile
@apehead
apehead / create-required-context.js
Created May 22, 2018 07:38 — forked from kentcdodds/create-required-context.js
create react context that has a validated consumer.
// create a React context Provider/Consumer pair that
// validates the consumer is rendered within a provider
function createRequiredContext(name) {
const Context = React.createContext()
function Consumer(props) {
return (
<Context.Consumer {...props}>
{val => {
if (!val) {
@apehead
apehead / FiniteMachine.js
Created January 10, 2018 08:47 — forked from ryanflorence/FiniteMachine.js
finite-machine.js
import React, { Component } from "react"
import { Machine } from "xstate"
import * as PropTypes from "prop-types"
class FiniteMachine extends Component {
machine = Machine(this.props.chart)
state = {
data: this.props.reducer(undefined, { type: "@init" }),
machineState: this.machine.getInitialState()
// makeRouteComponent.js
import { compile } from 'path-to-regexp'
import { Route } from 'react-router'
export const makeRouteComponent = config => Comp => {
Comp.__toPath = compile(config.path)
return <Route {...config} component={Comp}/>
}
export const pathTo = (Comp, params) => (
@apehead
apehead / pickProps.js
Created April 27, 2017 11:30
Pick props from object in ES6
function pickProps(res = {}, props = []) {
return props.reduce((acc, prop) => ({ ...acc, [prop]: res[prop] }), {});
}
export default pickProps;
@apehead
apehead / gist:e9962db60df531d86a74
Created October 19, 2015 09:50 — forked from stuart11n/gist:9628955
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@apehead
apehead / gist:ad4153dcb45746a399b9
Last active September 17, 2015 14:33 — forked from brian-mann/gist:7085402
The latest and greatest folder and file structure for Backbone / Marionette Apps
##Folder structure
/backbone
app.js
/apps
/entities
/lib
##Inside Apps
/apps
* create a new repo on github (CLI)
git init
git config user.name "myName" (use the --global option to set has a global parameter)
git config user.email "myEmail@to.to"
git add .
git commit -m "first commit"
git remote add origin git@github.com:Shaltz/myRepo.git
git push -u origin master
  • feat: A new feature
  • fix: A bug fix
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • refactor: A code change that neither fixes a bug or adds a feature
  • perf: A code change that improves performance
  • test: Adding missing tests
  • chore: Changes to the build process or auxiliary tools and libraries such as documentation generation
@apehead
apehead / icons.sass
Last active August 29, 2015 14:10 — forked from nickawalsh/icons.sass
@import compass
$icons: sprite-map("icons/*.png")
$icons-hd: sprite-map("icons-hd/*.png")
i
background: $icons
display: inline-block
@media (-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi)
background: $icons-hd
@apehead
apehead / app.js
Last active August 29, 2015 14:10 — forked from pixelhandler/app.js
var application_root = __dirname,
express = require("express"),
path = require("path"),
mongoose = require('mongoose');
var app = express.createServer();
// database
mongoose.connect('mongodb://localhost/ecomm_database');