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
@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)
}
@du5rte
du5rte / UserConnection.js
Last active November 9, 2023 10:29
GraphQL UserConnection with totalCount
import { GraphQLInt, GraphQLNonNull, GraphQLInputObjectType } from "graphql";
import { connectionDefinitions, connectionArgs } from "graphql-relay";
import UserType from "./UserType";
// References
// http://graphql.org/learn/pagination/
// http://dev.apollodata.com/react/pagination.html
// https://www.reindex.io/blog/relay-graphql-pagination-with-mongodb/
// https://github.com/graphql/graphql-relay-js
@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) {
const fs = require('fs')
const path = require('path')
const iconsPath = path.join(__dirname, 'src/icons')
function transform(input) {
const replacements = {
'svgs': 'Svg',
'circle': 'Circle',
@du5rte
du5rte / layout-challenge.md
Last active April 7, 2020 17:05
Layout Challenge

Layout Challenge

Create the layout attached below, using your preferred styling method (React or React Native). It does not need to be functional, rather concentrate on getting it as close to the design as possible.

layout

Branding

Branding guides, colors and icons, can be downloaded here

Font:

@du5rte
du5rte / signin-challenge.md
Created April 3, 2020 09:25
GraphQL Sign In Challenge 💫
@du5rte
du5rte / paths.js
Created February 25, 2019 14:23
Add support for lerna and/or yarn workspaces to react-scripts
// HACK:
// https://github.com/facebook/create-react-app/issues/1333#issuecomment-347970625
module.exports.appLernaModules = []
function searchModules(dir) {
fs.readdirSync(dir).forEach(folderName => {
if (folderName === 'react-scripts') return
if (folderName[0] === '.') return
# 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 / popup.js
Created September 18, 2018 12:42
Pop up
export default function popup(url, {name='', width=500, height=500}={}) {
// References
// https://developer.mozilla.org/en-US/docs/Web/API/Window/open
let options = `
width=${width},
height=${height},
left=${window.screenX + ((window.outerWidth - width) / 2)},
top=${window.screenY + ((window.outerHeight - height) / 2)}
`
@du5rte
du5rte / ratios.js
Last active July 25, 2018 10:35
Expand Ratios
// https://stackoverflow.com/questions/14224535/scaling-between-two-number-ranges
function withinRange(val, { min, max }) {
return (
val > max
? max
: val < min
? min
: val
);