Skip to content

Instantly share code, notes, and snippets.

View xeusteerapat's full-sized avatar
🤔
Focusing

Teerapat Prommarak xeusteerapat

🤔
Focusing
View GitHub Profile
@xeusteerapat
xeusteerapat / app.js
Created March 9, 2020 14:28
fetch api with Promise.all
const getData = url => {
return new Promise((resolve, reject) => {
fetch(url)
.then(response => resolve(response.json()))
.catch(error => reject(error));
});
};
const promise1 = getData('https://jsonplaceholder.typicode.com/users');
const promise2 = getData('https://jsonplaceholder.typicode.com/posts');
const fs = require('fs');
// create my own fetch function
const myFetch = path => {
return new Promise((resolve, reject) => {
let data = {
obj: fs.readFileSync(path, 'utf8'),
toJSON() {
return new Promise((resolve, reject) => {
resolve(JSON.parse(this.obj));
@xeusteerapat
xeusteerapat / esModule.js
Created March 23, 2020 06:06
Check my knowledge es2015 module
export const fruits = [
'🍇',
'🍈',
'🍉',
'🍊',
'🍋',
'🍌',
'🍍',
'🍎',
'🍏',
@xeusteerapat
xeusteerapat / todo.js
Created March 27, 2020 04:03
simple react todo app
import React from 'react';
class App extends React.Component {
state = {
text: '',
todos: []
};
handleChange = e => {
e.preventDefault();
@xeusteerapat
xeusteerapat / register.js
Created April 10, 2020 08:05
Example submit client form to database (mongo)
const handleSubmit = async e => {
e.preventDefault();
if (password !== confirmpassword) {
console.log('Password does not match');
} else {
const newUser = {
name,
email,
password
};
@xeusteerapat
xeusteerapat / autoScroll.js
Created May 31, 2020 06:12
Auto scroll mouse to the bottom of the page.
let intervalID = window.setInterval(function() {
window.scrollTo(0, document.body.scrollHeight)
}, 1000)
// to stop
window.clearInterval(intervalID)
@xeusteerapat
xeusteerapat / node_nginx_ssl.md
Created November 5, 2020 15:31 — forked from bradtraversy/node_nginx_ssl.md
Node app deploy with nginx & SSL

Node.js Deployment

Steps to deploy a Node.js app to DigitalOcean using PM2, NGINX as a reverse proxy and an SSL from LetsEncrypt

1. Sign up for Digital Ocean

If you use the referal link below, you get $10 free (1 or 2 months) https://m.do.co/c/5424d440c63a

2. Create a droplet and log in via ssh

I will be using the root user, but would suggest creating a new user

const asyncWrap = promise => promise.then(result => [null, result]).catch(err => [err])
const func = async () => {
const [error, result] = await asyncWrap(doAsyncThing())
}
const axios = require('axios');
const fs = require('fs/promises');
const main = async () => {
const { data } = await axios.get('API_ENDPOINT');
const tableOfContents = data.instance.details.toc.categories.map(item => {
return item.title;
});
@xeusteerapat
xeusteerapat / aws_serverless_recipes.md
Created August 24, 2021 10:59 — forked from nicolasdao/aws_serverless_recipes.md
Recipes for AWS Lambda with Serverless Framework. A series of recipes to get shit done using the Serverless Framework. Keywords: serverless recipe code recipes lambda lambdas function