Skip to content

Instantly share code, notes, and snippets.

View du5rte's full-sized avatar
🏠
Working from home

Duarte Monteiro du5rte

🏠
Working from home
View GitHub Profile
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@du5rte
du5rte / modernizrInit.js
Last active October 26, 2016 18:01
Modernizr initializer
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 February 19, 2017 00:52
Redux Image Load
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 February 26, 2017 21:40
GraphQL Subscriptions
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`
@du5rte
du5rte / autoStore.js
Last active March 8, 2023 12:10
Auto saving to localStorage with MobX
import mobx from "mobx"
import store from "store"
export default function(_this) {
let firstRun = true
// will run on change
mobx.autorun(() => {
// on load check if there's an existing store on localStorage and extend the store
if (firstRun) {
@du5rte
du5rte / jwt.js
Created March 15, 2017 10:58
Regex JWT
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..."
@du5rte
du5rte / Auth.js
Created March 16, 2017 16:38
mobX Auth Store
import mobx, { computed, observable, action } from "mobx"
import store from "store"
import autoStore from "./autoStore"
class Auth {
constructor() {
autoStore("authentication", this)
}
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]
@du5rte
du5rte / gist:2e580ea588a9f7843cdde9376efc6ff6
Last active April 26, 2017 16:41
dotenv improvements
// 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
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