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 / 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.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 / 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 / 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 / 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 / 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 / index.html
Created March 25, 2019 05:59
Filterable list app - <ul> part of index.html
<ul id="names" class="collection with-header">
<li class="collection-header">
<h5>A</h5>
<li class="collection-item">
<a href="#">Abe</a>
</li>
<li class="collection-item">
<a href="#">Atom</a>
</li>
<li class="collection-item">
@potikanond
potikanond / Members.js
Last active January 20, 2020 15:21
Members - Arrays of objects in JavaScript and JSON
const members = [
{
id: 1,
name: 'John Doe',
email: '[email protected]',
status: 'active'
},
{
id: 2,
name: 'Bob Williams',
@potikanond
potikanond / style.css
Created March 15, 2019 08:37
A Style sheet for JavaScript crash course
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, Helvetica, sans-serif;
line-height: 1.6;
}
@potikanond
potikanond / main.js
Last active March 21, 2019 06:41
Starting code - JavaScript Array and High-order functions
// Add the following element at the end of <body> element in an html file
// <script src="main.js"></script>
const companies= [
{name: "Company One", category: "Finance", start: 1981, end: 2004},
{name: "Company Two", category: "Retail", start: 1992, end: 2008},
{name: "Company Three", category: "Auto", start: 1999, end: 2007},
{name: "Company Four", category: "Retail", start: 1989, end: 2010},
{name: "Company Five", category: "Technology", start: 2009, end: 2014},
{name: "Company Six", category: "Finance", start: 1987, end: 2010},