Skip to content

Instantly share code, notes, and snippets.

View danielnmai's full-sized avatar
💻
Working on React and Node

Daniel Mai danielnmai

💻
Working on React and Node
View GitHub Profile
@danielnmai
danielnmai / reactComponent.js
Last active September 8, 2018 16:47
a simple React component
import React from 'react'
import s from './styles/footer.css'
import withStyles from 'isomorphic-style-loader/lib/withStyles'
const Footer = (props) => {
return (
<div className='footer'>
<p>Copyright @ DANIEL MAI - 2018 All Rights Reserved. </p>
</div>
)
@danielnmai
danielnmai / ContextProvider.js
Created September 8, 2018 16:45
Context Provider for App.js
import React from 'react';
import PropTypes from 'prop-types'
import App from './App'
class ContextProvider extends React.Component {
static childContextTypes = {
insertCss: PropTypes.func,
}
getChildContext() {
@danielnmai
danielnmai / client_index.js
Created September 8, 2018 16:44
Root file for client side
import React from 'react';
import { hydrate } from 'react-dom'
import App from './App.js'
import ContextProvider from './ContextProvider.js'
const context = {
insertCss: (...styles) => {
const removeCss = styles.map(x => x._insertCss());
return () => {
removeCss.forEach(f => f());
@danielnmai
danielnmai / server_index.js
Last active September 8, 2018 16:44
Express server for React SSR
import express from "express"
import { renderToString } from "react-dom/server"
import React from 'react'
import App from '../App.js'
import ContextProvider from '../ContextProvider.js'
const app = express()
//Serve the app with the public bundle.js
app.use(express.static("online/dist/"))
@danielnmai
danielnmai / TIL
Created September 26, 2017 03:51
Today I Learned
git add -p
This is useful!
@danielnmai
danielnmai / gist:cb77615fa4af2dd6eea9d5eb4bf90d8b
Created August 4, 2017 04:57
The Difference Engine - What I learned
Create alias to make shortcut to regular-typed commands
Steps:
1. Go to root directory ( cd ~ )
2. Open the bash profile ( subl ~/.bash_profile )
3. Create alias for command shortcut (for example, the line /alias gs='git status'/ will add an alias "gs" to the command "git status", so you can use "gs" to achieve the same purpose as "git status"
@danielnmai
danielnmai / History|-12311c03|entries.json
Last active April 27, 2022 23:40
Today I learned - Week 10
{"version":1,"resource":"file:///Users/danielmai/infuse/crystal-inventory-service/.env.development","entries":[{"id":"QSmg.development","timestamp":1649700882559},{"id":"gPX2.development","timestamp":1649707291121},{"id":"Dbfi.development","timestamp":1649707342462}]}
Rails form tag:
datetime_local_field_tag
add:
/* global angular */ if having problem with Linter
Unit Testing
It is better to write modular codes
@danielnmai
danielnmai / TIL_week8
Last active June 21, 2017 01:31
Today I Learned - Week 8
--------6/18/17---------
JavaScript is asyncronous: it does not wait for a function to finish before starting another one.
Ruby runs code from top to bottom (synchronous)
JavaScript runs code asynchronously.
anonymous function: a function with no name
function() {
console.log('Hello');
}
@danielnmai
danielnmai / TIL_week7
Created June 13, 2017 04:30
Today I Learned - Week 7
---------6/12/2017------------
Javascript
It can return unexpected results
> 5 + "2" => "52"
> 5 - "2" => 3
parseInt("342")
342.toString()
type comparison: 5 === '5' => false (strict)
5 == '5' => true (loose)