Skip to content

Instantly share code, notes, and snippets.

@kunxin-chor
kunxin-chor / index.js
Created June 19, 2023 07:25
Starting template for Express
const express = require('express');
const ejs = require('ejs');
const app = express();
app.set('view engine', 'ejs');
app.get('/', function(req,res){
res.send("Hello World")
})
@kunxin-chor
kunxin-chor / db.sql
Last active June 22, 2023 01:41
Sample database
CREATE TABLE artists (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
birth_year INT,
country VARCHAR(255)
) engine=innoDB;
ALTER TABLE `artists` ADD `preferred_medium` VARCHAR(255) NULL AFTER `country`;
@kunxin-chor
kunxin-chor / index.html
Created March 31, 2023 08:05
Sample index HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fictional Business</title>
</head>
<body>
<header id="main-header">
<h1>Fictional Business</h1>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
@kunxin-chor
kunxin-chor / index.js
Created December 5, 2022 12:15
Boilerplate for Express Application with HBS and Wax on
// 1. SETUP EXPRESS
const express = require('express');
const hbs = require('hbs');
const wax = require('wax-on');
// 1a. create the app
const app = express();
// 1b setup our view engine (aka template engine)
// tell Express that we are using hbs
[
{
"_id": "1001",
"name":"Tan Ah Kow",
"occupation":"Manager",
"students":[
{
"_id":"2002",
"name":"Benjamin Tan",
"dob":"2018-04-22",
@kunxin-chor
kunxin-chor / index.html
Created October 12, 2022 07:03
Boilerplate Leaflet
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- leaflet css -->
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
{"10009":[103.81722,1.2821,"Bt Merah Int"],"10011":[103.8375,1.27774,"Bef Neil Rd"],"10017":[103.83763,1.27832,"Aft Hosp Dr"],"10018":[103.8386,1.27901,"Outram Pk Stn Exit F/SGH"],"10021":[103.83839,1.27745,"Blk 3"],"10041":[103.83519,1.27606,"Bef Kampong Bahru Ter"],"10049":[103.83484,1.27623,"Opp Kampong Bahru Ter"],"10051":[103.83214,1.27741,"Blk 149"],"10059":[103.83275,1.2774,"Opp Blk 149"],"10061":[103.82949,1.2786,"Blk 140"],"10069":[103.83008,1.27855,"Opp Blk 140"],"10071":[103.82639,1.28045,"Blk 111"],"10079":[103.82709,1.2804,"Blk 201"],"10081":[103.82242,1.28228,"Opp Blk 120"],"10089":[103.82166,1.28292,"Blk 119"],"10091":[103.81784,1.28394,"Bt Merah Town Ctr"],"10099":[103.81766,1.28421,"Opp Bt Merah Town Ctr"],"10101":[103.81378,1.28506,"Opp Bt Merah Sec Sch"],"10109":[103.81371,1.28535,"Bt Merah Sec Sch"],"10111":[103.80935,1.28593,"Opp Blk 28"],"10119":[103.81123,1.28598,"Opp Pacific Tech Ctr"],"10121":[103.82891,1.2826,"Blk 126 CP"],"10129":[103.82857,1.28232,"Blk 121"],"10131":[103.80687,1.28
@kunxin-chor
kunxin-chor / index.js
Created October 7, 2022 07:22
How to get the checked value from a radio button
let radioButtons = document.querySelectorAll(".day");
let selectedDay = "";
for (let rb of radioButtons) {
if (rb.checked) {
selectedDay = rb.value;
}
}
@kunxin-chor
kunxin-chor / MongoUtil
Created June 23, 2022 07:31
TGC 18 MongoUtil
// require('mongodb') will return a Mongo object
// the Mongo client contains many other objects (aka properties)
// but we are only interested in the MongoClient
// hence put `.MongoClient` at the back of the require
const MongoClient = require('mongodb').MongoClient;
async function connect(mongoUri, dbName) {
const client = await MongoClient.connect(mongoUri, {
"useUnifiedTopology": true // there were different versions of Mongo
// when this is true we don't have to care about those versions