Skip to content

Instantly share code, notes, and snippets.

View potikanond's full-sized avatar

D. Potikanond potikanond

  • Computer Engineering, CMU
  • Thailand
View GitHub Profile
@potikanond
potikanond / fetch_api.js
Last active March 30, 2019 09:06
JavaScript "Fetch API" tutorial
/* References:
https://developers.google.com/web/updates/2015/03/introduction-to-fetch
https://scotch.io/tutorials/how-to-use-the-javascript-fetch-api-to-get-data
https://medium.freecodecamp.org/a-practical-es6-guide-on-how-to-perform-http-requests-using-the-fetch-api-594c3d91a547
*/
/* Making Simple GET Request:
// fetch(url) // Call the fetch function passing the url of the API as a parameter
// .then(function() {
// // Your code for handling the data you get from the API
@potikanond
potikanond / xhr.js
Created March 30, 2019 08:34
JavaScript "XHR" tutorial
/* References:
https://developers.google.com/web/updates/2015/03/introduction-to-fetch
https://www.w3schools.com/xml/xml_http.asp
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
*/
function reqListener() {
var data = JSON.parse(this.responseText);
console.log(data);
}
@potikanond
potikanond / app.js
Last active April 1, 2019 12:04
Node.js - More flexible HTTP server#2 (lab tutorial)
const http = require('http');
const fs = require('fs');
const server = http.createServer((req, res) => {
// -------- more flexible way ---------
// Build file path
let filePath = path.join(
__dirname,
'public',
@potikanond
potikanond / app.js
Created April 1, 2019 12:02
Node.js - Simple HTTP Server#1 (lab tutorial)
const http = require('http');
const fs = require('fs');
const path = require('path');
const server = http.createServer( (req,res) => {
console.log(req.url);
if(req.url === '/') {
// res.writeHead(200, { 'Content-Type': 'text/html'});
// res.end('<h1>This is index.html</h1>');
@potikanond
potikanond / main.cpp
Created April 2, 2019 14:56
ENGR201 - Sample c++ program for calculating SD using function
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;
void myFunc1(int[], int);
double myFunc2(int[], int);
double myFunc3(int[], int, double);
@potikanond
potikanond / index.handlebars
Created April 21, 2019 03:46
Express Tutorial - "index" handlebars template
<h1 class="text-center mb-3">{{title}}</h1>
<form action="/api/members" method="POST" class="mb-4">
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" class="form-control" id="">
</div>
<div class="form-group">
<label for="email">Email</label>
@potikanond
potikanond / main.handlebars
Created April 21, 2019 04:13
Express Tutorial - "main" handlebars template
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>Members App</title>
</head>
<body>
@potikanond
potikanond / index.html
Last active May 9, 2025 03:39
JavaScript - Fetch API Tutorial (HTML, JSON)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<!-- 9. add bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
@potikanond
potikanond / index.html
Last active January 14, 2020 06:50
Web1 - Simple Firefox Page
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My test page</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
</head>
<body>
<h1>Mozilla is Cool!</h1>
@potikanond
potikanond / README-js-crash.md
Last active January 14, 2020 06:25
JavaScript Tutorial 2020

JavaScript Crash Course

Use Console tab for single line instruction. Executing single instruction at a time.

// Warning
alert('Hello');

// Confirm?
let val = confirm("Do you want to continue ?");