Skip to content

Instantly share code, notes, and snippets.

View mhaagens's full-sized avatar

Martin mhaagens

  • AmmaCreative
  • Oslo, Norway
View GitHub Profile
@mhaagens
mhaagens / Dockerfile
Created October 13, 2017 06:26
Node Frontend Docker Quickstart
FROM node:alpine
WORKDIR /code
run apk --no-cache add --virtual native-deps \
g++ gcc libgcc libstdc++ linux-headers make python && \
npm install --quiet node-gyp -g && \
npm rebuild node-sass --force && \
apk del native-deps
CMD ["yarn", "start"]
EXPOSE 9000
@mhaagens
mhaagens / HOC.js
Created August 10, 2017 11:57 — forked from Restuta/HOC.js
React HOC (Higher Order Component) Example
/* HOC fundamentally is just a function that accepts a Component and returns a Component:
(component) => {return componentOnSteroids; } or just component => componentOnSteroids;
Let's assume we want to wrap our components in another component that is used for debugging purposes,
it just wraps them in a DIV with "debug class on it".
Below ComponentToDebug is a React component.
*/
//HOC using Class
//it's a function that accepts ComponentToDebug and implicitly returns a Class
let DebugComponent = ComponentToDebug => class extends Component {
@mhaagens
mhaagens / AnimatedRoute.js
Last active July 8, 2017 18:10
AnimatedRoute Wrapper
import React from "react";
import { Route } from "react-router-dom";
import TransitionGroup from "react-transition-group/TransitionGroup";
import { firstChild } from "../../utils/helpers";
const AnimatedRoute = ({ component: Component, exact, path }) => (
<Route
exact={exact}
path={path}
render={({ match, ...rest }) => (
@mhaagens
mhaagens / gist:a21cc02fdd068862fa15d1860799184c
Created June 8, 2017 17:18
Pseduo-code Styled Components + Animated
const CustomDiv = styled(Animated.view)`
transform: ${props => `rotate(props.rotateDeg)`}
`;
class App extends Component {
constructor(props) {
super(props)
this.state = {
rotate: new Animated.Value(0)
}
import React, { Component } from "react";
class AutoComplete extends Component {
constructor(props) {
super(props)
this.state = {
query: ""
}
}
import http from 'http';
import app from './server';
const port = 3000;
const server = http.createServer(app.callback()).listen(3000);
if (module.hot) {
module.hot.accept('./server', () => {
server.removeAllListeners('request', server);
@mhaagens
mhaagens / gist:61f88e3fbfddbe2c00708f3ebd099be4
Last active September 12, 2018 23:56
Transition Motion React Router 4 Route Transition
const FadeRoute = ({ component: Component, ...rest }) => {
return (
<Route {...rest} children={({ location, match }) => (
<TransitionMotion
willEnter={() => {return {opacity: 0, translateX: 24}}}
willLeave={() => {return {opacity: spring(0, animationPresets.out), translateX: spring(24)}}}
defaultStyles={[ {
key: location.pathname,
style: { opacity: 0, translateX: 24},