Skip to content

Instantly share code, notes, and snippets.

@nikhilsu
nikhilsu / iteration.js
Created November 26, 2018 09:28
Example of JS object iteration
var obj = { 'key1': 'value1', 'key2': 'value2' };
Object.keys(obj).forEach(function(key) {
var value = obj[key];
console.log(key, value);
});
@nikhilsu
nikhilsu / state_info.js
Last active November 26, 2018 08:47
Information of states
var state_info = {
'AL': {'lat': 32.3792233, 'lng': -86.3077368, 'capital': 'Montgomery'},
'AK': {'lat': 58.3019444, 'lng': -134.4197221, 'capital': 'Juneau'},
'AZ': {'lat': 33.4483771, 'lng': -112.0740373, 'capital': 'Phoenix'},
'AR': {'lat': 34.7464809, 'lng': -92.28959479999999, 'capital': 'Little Rock'},
'CA': {'lat': 38.5815719, 'lng': -121.4943996, 'capital': 'Sacramento'},
'CO': {'lat': 39.7392358, 'lng': -104.990251, 'capital': 'Denver'},
'CT': {'lat': 41.7658043, 'lng': -72.6733723, 'capital': 'Hartford'},
'DE': {'lat': 39.158168, 'lng': -75.5243682, 'capital': 'Dover'},
'FL': {'lat': 30.4382559, 'lng': -84.28073289999999, 'capital': 'Tallahassee'},
@nikhilsu
nikhilsu / schema.sql
Created November 6, 2018 00:38
Create schema for Postgres
CREATE TABLE if not exists store
( id serial,
sname varchar(40) not null,
qty integer not null,
price float not null, primary key (id));
INSERT INTO store (sname, qty, price)
VALUES ('apple', 10, 1), ('pear', 5, 2), ('banana', 10, 1.5), ('lemon', 100, 0.1), ('orange', 50, 0.2);
@nikhilsu
nikhilsu / store.js
Last active November 2, 2018 15:58
CSCI 3308 Lab 9 store.js Delete
var express = require('express');
var db = require('../database');
var app = express();
module.exports = app;
app.get('/', function (request, response) {
// TODO: Initialize the query variable with a SQL query
// that returns all the rows in the ‘store’ table
var query = 'select * from store';
@nikhilsu
nikhilsu / store.js
Last active November 2, 2018 15:59
CSCI 3308 Lab 9 Update
var express = require('express');
var db = require('../database');
var app = express();
module.exports = app;
app.get('/', function (request, response) {
// TODO: Initialize the query variable with a SQL query
// that returns all the rows in the ‘store’ table
var query = 'select * from store';
@nikhilsu
nikhilsu / add.ejs
Created October 30, 2018 22:30
CSCI 3308 Lab 9 add.ejs
<!--Including Header partial-->
<%- include ../layouts/header.ejs %>
<% if (messages.error) { %>
<p style="color:red"><%- messages.error %></p>
<% } %>
<% if (messages.success) { %>
<p style="color:green"><%- messages.success %></p>
<% } %>
@nikhilsu
nikhilsu / store.js
Created October 30, 2018 22:28
CSCI 3308 Lab 9 store.js INSERT
var express = require('express');
var db = require('../database');
var app = express();
module.exports = app;
app.get('/', function (request, response) {
// TODO: Initialize the query variable with a SQL query
// that returns all the rows in the ‘store’ table
var query = 'select * from store';
@nikhilsu
nikhilsu / list.ejs
Last active October 30, 2018 22:11
CSCI lab 9 list.ejs SELECT
<!-- Including Header Partial-->
<%- include ../layouts/header.ejs %>
<!-- Using if-check to see if an error occurred and displaying appropriate message-->
<% if (messages.error) { %>
<p style="color:red"><%- messages.error %></p>
<% } %>
<% if (messages.success) { %>
<p style="color:blue"><%- messages.success %></p>
<% } %>
@nikhilsu
nikhilsu / store.js
Created October 30, 2018 21:19
CSCI lab 9 store.js Select query
var express = require('express');
var db = require('../database');
var app = express();
module.exports = app;
app.get('/', function (request, response) {
// TODO: Initialize the query variable with a SQL query
// that returns all the rows in the ‘store’ table
var query = 'select * from store';
@nikhilsu
nikhilsu / index.ejs
Last active October 30, 2018 21:36
CSCI 3308 Lab 9 index.ejs
<html>
<head>
<!-- ‘title’ is the data that is passed from the index.js during the response.render function call -->
<title><%= title %></title>
</head>
<body>
<div>
<a href="/">Home</a> |
<a href="/store/add">Add item</a> |
<a href="/store">All items</a>