Skip to content

Instantly share code, notes, and snippets.

🎯
Busy
Focusing

Truong Hoang Dung revskill10

  • Freelancer
  • Haiphong, Vietnam
View GitHub Profile
@revskill10
revskill10 / get-data-from-tree.js
Created Mar 15, 2019 — forked from hamlim/get-data-from-tree.js
Get data from tree fork with support for React.createContext
View get-data-from-tree.js
// Forked from react-apollo get-data-from-tree
import React from 'react';
const getProps = element => {
return element.props || element.attributes;
};
const isReactElement = element => {
return !!element.type;
};
const isComponentClass = Comp => {
return (
@revskill10
revskill10 / fetch-graphql.js
Created Feb 6, 2019 — forked from stubailo/fetch-graphql.js
Call a GraphQL API with fetch
View fetch-graphql.js
require('isomorphic-fetch');
fetch('https://1jzxrj179.lp.gql.zone/graphql', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: '{ posts { title } }' }),
})
.then(res => res.json())
.then(res => console.log(res.data));
@revskill10
revskill10 / unfuckReact.js
Created Jan 22, 2019 — forked from barneycarroll/unfuckReact.js
React components are so fucking stupid, it's unbelievable. 3 months with this library version 15 and the glaring stupidity of the API just keeps coming in waves. Fixing some of this stuff – just for the sake of internal consistency – would have been so simple. The number of hoops you're required to jump through for trivial shit. Ugh.
View unfuckReact.js
const mounted = new WeakSet()
export default const unfucker = (component, displayName = component.displayName || component.name || 'React.Component') => {
const host = {
[displayName] : class extends React.Component {
constructor(){
this.state = {}
component.apply(this, arguments)
}
@revskill10
revskill10 / index.html
Created Dec 15, 2018
Nutrition Facts Table in HTML & CSS
View index.html
<img src="https://s.cdpn.io/3/NutritionFacts.gif" class="image">
<section class="performance-facts">
<header class="performance-facts__header">
<h1 class="performance-facts__title">Nutrition Facts</h1>
<p>Serving Size 1/2 cup (about 82g)
<p>Serving Per Container 8</p>
</header>
<table class="performance-facts__table">
<thead>
@revskill10
revskill10 / next.config.js
Last active Dec 9, 2018
NextJS config for Now V2: assetPrefix, custom less theme, apollo, styled-icons
View next.config.js
const dev = process.env.NODE_ENV !== 'production'
const prefix = dev ? '' : process.env.WWW_PREFIX
const { PHASE_PRODUCTION_SERVER } =
process.env.NODE_ENV === "development"
? require("next/constants")
: require("next-server/constants");
const sharedConfig = {
assetPrefix: prefix,
@revskill10
revskill10 / buildSitemap.js
Created Dec 8, 2018 — forked from evantahler/buildSitemap.js
35 lines to build a sitemap for next.js projects
View buildSitemap.js
#! /usr/bin/env node
// I am ./bin/buildSitemap.js
const path = require('path')
const glob = require('glob')
const fs = require('fs')
const SITE_ROOT = process.env.SITE_ROOT || 'https://www.actionherojs.com'
const SOURCE = process.env.SOURCE || path.join(__dirname, '..', 'pages', '/**/*.js')
const DESTINATION = process.env.DESTINATION || path.join(__dirname, '..', 'static', 'sitemap.xml')
@revskill10
revskill10 / better-nodejs-require-paths.md
Created Nov 22, 2018 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js
View better-nodejs-require-paths.md

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@revskill10
revskill10 / Link.js
Last active Nov 20, 2018
React-i18next
View Link.js
@revskill10
revskill10 / nginx.conf
Created Nov 11, 2018 — forked from nrollr/nginx.conf
NGINX config for SSL with Let's Encrypt certs
View nginx.conf
# Advanced config for NGINX
server_tokens off;
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options nosniff;
# Redirect all HTTP traffic to HTTPS
server {
listen 80;
server_name www.domain.com domain.com;
return 301 https://$host$request_uri;
@revskill10
revskill10 / server.js
Created Nov 8, 2018 — forked from magicspon/server.js
using https with next
View server.js
const https = require('https')
const { parse } = require('url')
const next = require('next')
const fs = require('fs')
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
const options = {
You can’t perform that action at this time.