Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Duarte Monteiro du5rte

🏠
Working from home
View GitHub Profile
View init.coffee
# 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 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`
@du5rte
du5rte / autoStore.js
Last active Oct 14, 2021
Auto saving to localStorage with MobX
View autoStore.js
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) {
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..."
@du5rte
du5rte / Auth.js
Created Mar 16, 2017
mobX Auth Store
View Auth.js
import mobx, { computed, observable, action } from "mobx"
import store from "store"
import autoStore from "./autoStore"
class Auth {
constructor() {
autoStore("authentication", this)
}
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