Skip to content

Instantly share code, notes, and snippets.

View juandc's full-sized avatar
🏠

Juan David Castro juandc

🏠
View GitHub Profile

Folder Structure

Motivations

  • Clear feature ownership
  • Module usage predictibility (refactoring, maintainence, you know what's shared, what's not, prevents accidental regressions, avoids huge directories of not-actually-reusable modules, etc)

Accessibility, IDs, and Server Rendering in React

For better or for worse, many WAI-ARIA patterns depend on ID's to connect elements together.

For example (without ARIA):

<label for="first-name">First Name</label>
<input id="first-name"/>
@aswinmprabhu
aswinmprabhu / firebase-react-class.js
Last active May 8, 2019 21:31
Firebase real-time chatroom app using react class based components
class App extends Component {
constructor() {
super();
this.state = {
joined: false,
nickname: "",
email: "",
msg: "",
messages: {},
};
@israellias
israellias / platzi_boxes.rb
Last active December 28, 2018 16:07
Platzi - Reto 8
# Platzi - Reto 8 Diciembre 23
# @author: @israellias
# ruby_version: 2.5.3
#regalaconocimiento
module Model
class Box < Struct.new(:name, :money, :weight)
end
class Combination < Struct.new(:boxes)
import withData from '@/lib/withData'
import { ApolloClient } from 'apollo-boost'
import App, { AppProps, Container } from 'next/app'
import { ApolloProvider } from 'react-apollo'
export default withData(
class extends App<MyAppProps> {
public static async getInitialProps({ Component, ...ctx }) {
let pageProps = {}
@igordata
igordata / server.js
Created November 4, 2018 11:11
How to cahce all pages with next.js
const express = require('express');
const next = require('next');
const LRUCache = require('lru-cache');
const port = parseInt(process.env.PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({dev});
const handle = app.getRequestHandler();
// This is where we cache our rendered HTML pages
// NOTE: you will NOT write code like this when using suspense
// instead, you'll use react-cache (not yet officially published)
// it'll handle things like pre-loading, handling rapid re-renders, etc.
const cache = {}
function FetchPokemon({pokemonName}) {
const pokemon = cache[pokemonName]
if (!pokemon) {
const promise = fetchPokemon(pokemonName).then(
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App/App';
import './index.css';
const render = () => {
ReactDOM.render(<App />, document.getElementById('root'));
}
if (
@mhaagens
mhaagens / authentication_middleware.js
Last active April 22, 2020 10:14
Auth middleware
import jwt from "jsonwebtoken";
import User from "@server/models/user_model";
const PRODUCTION = process.env.NODE_ENV === "production";
export default (options) => async (req, res, next) => {
const refreshToken = req.cookies["refresh_token"];
const accessToken = req.cookies["access_token"];
const csrfHeader = req.get("X-Csrf-Token");
@juandc
juandc / detectmotionurl.js
Created August 14, 2018 15:40 — forked from wagyu298/detectmotionurl.js
AWS Rekognition detectModerationLabels example for Node.js
#!/usr/bin/env node
const request = require('request');
const AWS = require('aws-sdk');
const rekognition = new AWS.Rekognition({
// Detect moderation labels is available on AWS region us-east-1, us-west-2 and eu-west-1
region: "us-west-2",
accessKeyId: "YOUR accessKeyId",
secretAccessKey: "YOUR secretAccessKey"