Skip to content

Instantly share code, notes, and snippets.

@kunxin-chor
kunxin-chor / index.js
Created June 6, 2022 03:42
TGC 18 Express Boilerplate
const express = require('express');
const hbs = require('hbs');
const waxOn = require('wax-on');
let app = express(); //create the express application
app.set('view engine', 'hbs'); // inform express that we are using hbs as the view engine
waxOn.on(hbs.handlebars); // enable wax-on for handlebars (for template inheritance)
waxOn.setLayoutPath('./views/layouts') // inform wax-on where to find the layouts
@kunxin-chor
kunxin-chor / gist:b64e5fd74890400de782997a52ee7a76
Last active March 30, 2022 07:46
For each product, find the customer that purchases the most
select productCode as p, customerNumber as c from orders join orderdetails
on orders.orderNumber = orderdetails.orderNumber
group by productCode, customerNumber
having (productCode, customerNumber) = (
select productCode, customerNumber
from orders join orderdetails ON orders.orderNumber = orderdetails.orderNumber
where productCode = p
group by productCode, customerNumber
order by sum(quantityOrdered) desc
limit 1
@kunxin-chor
kunxin-chor / gist:9f5c424f13ecaf0c5ae72a45cc62aa7c
Created March 30, 2022 04:13
Find best selling product for each month
( SELECT productCode, year(orderDate) as orderYear, month(orderDate) as orderMonth
FROM orderdetails
JOIN orders on orders.orderNumber = orderdetails.orderNumber
GROUP BY productCode, YEAR(orderDate), MONTH(orderDate)
HAVING productCode = ( SELECT productCode
FROM orderdetails JOIN orders on orderdetails.orderNumber = orders.orderNumber
WHERE year(orderDate) = orderYear AND month(orderDate) = orderMonth
GROUP BY productCode
ORDER BY COUNT(*) DESC
LIMIT 1
function renderSkillsDropdown(skills) {
let s = '';
for (let eachSkill in skills) {
let skillData = skills[eachSkill];
s += `<option value='${eachSkill}'>${eachSkill} (Rank: ${skillData.rank})</option>`
}
return s;
}
function renderCharacteristicsDropdown(characteristics) {
@kunxin-chor
kunxin-chor / index.js
Created February 17, 2022 07:51
Ultra Simple Express Server
const express = require('express');
const hbs = require('hbs');
const waxOn = require('wax-on');
const app = express();
app.get('/', function(req,res){
res.send("It's alive!")
})
@kunxin-chor
kunxin-chor / index.html
Last active May 22, 2022 03:11
Counter index.html for question 6
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Count Me!</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div id="box">0</div>
@kunxin-chor
kunxin-chor / gist:c43379a9afa35ef434a2d26e11094fe7
Created October 6, 2021 12:44
Bootstrap 5 Navbar used in the walkthrough
<nav class="navbar navbar-expand-sm navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="javascript:void(0)">Logo</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#mynavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="mynavbar">
<ul class="navbar-nav me-auto">
<li class="nav-item">
<a class="nav-link" href="javascript:void(0)">Link</a>
<!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">
1. print(2 + 3)
=> print(5)
2. print(2 * 5 + 4)
=> print(10 + 4)
=> print(14)
3. print(3 + 5 * 4 / 2 )
=> print(3 + 20 / 2)
=> print(3 + 10)
@kunxin-chor
kunxin-chor / index.js
Created July 22, 2021 11:25
Express Template
// import in the packages
const express = require('express');
const hbs = require('hbs');
const wax = require('wax-on')
let app = express();
app.set('view engine', 'hbs');
// Inform Express where to find static images, css and
// client-side (ie. browser)