Skip to content

Instantly share code, notes, and snippets.

View longnt80's full-sized avatar

Long Nguyen longnt80

  • Melbourne, Australia
View GitHub Profile
@longnt80
longnt80 / promise.js
Last active April 2, 2019 22:28
Promise polyfill implementtion
class MyPromise {
constructor(cb) {
this.value;
this.state;
this.fulfilledCB = [];
this.rejecteddCB = [];
cb(this.resolve, this.reject);
}
then = (successCB, failureCB) => {
@longnt80
longnt80 / basic_auth_nodejs_test.js
Created January 1, 2019 00:30 — forked from charlesdaniel/basic_auth_nodejs_test.js
Example of HTTP Basic Auth in NodeJS
var http = require('http');
var server = http.createServer(function(req, res) {
// console.log(req); // debug dump the request
// If they pass in a basic auth credential it'll be in a header called "Authorization" (note NodeJS lowercases the names of headers in its request object)
var auth = req.headers['authorization']; // auth is in base64(username:password) so we need to decode the base64
console.log("Authorization Header is: ", auth);
import React from 'react';
import { Formik } from 'formik';
import history from '../../../history';
import ProgressBar from './ProgressBar';
class Wizard extends React.Component {
static Page = ({ children, parentState }) => {
return children(parentState);
};
@longnt80
longnt80 / gist:faec57840a72c64c3ab7753114f464cf
Created November 10, 2017 07:49
8 immutable array operations
clone = x => [...x]
push = y => x => [...x, y]
pop = x => x.slice(0, -1)
unshift = y => x => [y, ...x]
shift = x => x.slice(1)
sort = f => x => [...x].sort(f)
delete = i => x => [...x.slice(0, i), ...x.slide(i+1)]
splice = (s, c, ...y) => x => [...x.slice(0,s), ...y, ...x.slice(s+c)]
@longnt80
longnt80 / SingleItemEdit.js
Last active November 2, 2017 02:38
Component for recipe box app
import React, { Component } from 'react';
import '../styles/SingleItemEdit.css';
import Paper from 'material-ui/Paper';
import FlatButton from 'material-ui/FlatButton';
import TextField from 'material-ui/TextField';
const defaultContent = {
name: '',
description: '',
@longnt80
longnt80 / index.html
Last active June 13, 2017 01:08
JavaScript Calculator
<div class="container">
<div class="title">Calculator</div>
<div class="input-box">
<div class="ans"></div>
<div class="input"></div>
</div>
<div class="button-box">
<div class="row">
<button value="ac">AC</button>
<button value="ce">CE</button>