Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Duarte Monteiro du5rte

🏠
Working from home
View GitHub Profile
@du5rte
du5rte / modernizrInit.js
Last active Oct 26, 2016
Modernizr initializer
View modernizrInit.js
import './modernizr'
// Modernizr
// https://modernizr.com/docs
Modernizr.addTest('support', function() {
if (
Modernizr.svg &&
Modernizr.cssanimations &&
Modernizr.boxsizing &&
Modernizr.flexbox &&
@du5rte
du5rte / ImageLoad.jsx
Last active Feb 19, 2017
Redux Image Load
View ImageLoad.jsx
import React, { Component, PropTypes } from 'react'
import { connect } from 'react-redux'
import { actionsCreator } from 'actions'
// References
// http://blog.teamtreehouse.com/learn-asynchronous-image-loading-javascript
@connect(
state => state,
dispatch => actionsCreator(dispatch)
@du5rte
du5rte / Render.jsx
Last active Feb 26, 2017
GraphQL Subscriptions
View Render.jsx
import React, { Component, PropTypes } from 'react';
import { graphql } from 'react-apollo'
import gql from 'graphql-tag'
import update from 'immutability-helper'
import { Toggler, colors } from "./Toggler"
import View from "react-flexbox"
@graphql(gql`
View jwt.js
const authorization = "Bearer abcefghijklmnopqrstu.vwxyzABCDEFGHIJKLMNOPQ.RSTUVWXYZ0123456789"
// (?:__) no selection group
// (__)? optional selection group
// (__) selection group
// searchers for digits seperated by three dots xx.xx.xx with an optional "Bearer "
// retrieve only the jwt (without Bearer)
const jwt = authorization.match(/(?:Bearer\s+)?(\w+\.\w+\.\w+)/)[1] // "abcef..."
View gist:713ceb731a9a33e24dd76d9838daf51a
const ProfileType = new GraphQLObjectType({
name: 'Profile',
description: 'User Profile',
fields: {
email: {type: new GraphQLNonNull(GraphQLString)},
username: {
type: new GraphQLNonNull(GraphQLString),
resolve(profile) {
return profile.split("@")[0]
View gist:2e580ea588a9f7843cdde9376efc6ff6
// better file checker
// https://nodejs.org/dist/latest-v7.x/docs/api/fs.html#fs_fs_readfilesync_file_options
fs.accessSync(path.resolve(__dirname,'./config-local.json'), fs.R_OK);
// add .env.js
View fibonacci.js
let x = 0
console.log(x)
let y = 1
console.log(y)
let z = 0
for (let i=0; i < 20; i++) {
z = x + y
@du5rte
du5rte / HoverDecorator.jsx
Last active May 8, 2017 — forked from laem/HoverDecorator.jsx
React Hover Component Decorator
View HoverDecorator.jsx
import React, { Component } from "react"
export default function hoverDecorator(InitialComponent) {
return class HoverDecorator extends Component {
constructor() {
super()
this.state = {
hover: false
}
View mergeObjectArraysByName.js
const stateFiles = [
{name: 'john'},
{name: 'lewis'},
]
const files = [
{name: 'ana'},
{name: 'john', email: "john@mail.com"},
]