Skip to content

Instantly share code, notes, and snippets.

View SalithaUCSC's full-sized avatar
🚩
Enjoying Life

Salitha Chathuranga SalithaUCSC

🚩
Enjoying Life
View GitHub Profile
@SalithaUCSC
SalithaUCSC / app.js
Last active September 25, 2018 19:19
Simple express server implementation
// Load express module
const express = require('express');
// Initialize app
const app = express();
// Initialize port
const port = 3000;
// Initialize paths
const path = require('path');
// Initialize public directory
@SalithaUCSC
SalithaUCSC / post.js
Last active September 24, 2018 09:09
Schema for a post collection in MongoDB
const mongoose = require('mongoose');
// Schema
let postSchema = mongoose.Schema({
title: {
type: String,
required: true
},
author: {
type: String,
required: true
@SalithaUCSC
SalithaUCSC / router.js
Last active September 25, 2018 20:07
Router functions for an API created for blog posts.
const express = require('express');
// Initialize router
const router = express.Router();
// Load models
let Post = require('../models/post');
router.get('/posts', function (req, res) {
let posts = Post.find({}, function(err, posts){
if(err){
console.log(err);
@SalithaUCSC
SalithaUCSC / object_array.js
Created September 26, 2018 17:36
How to create an object array using 3 arrays.
var classes = ["A", "B", "C"];
var presentees = [40, 20, 30];
var absentees = [20,10, 10];
var attendance = [];
for (var i = 0; i < classes.length; i++) {
var att_obj = {};
att_obj["class"] = classes[i];
att_obj["presentees"] = presentees[i];
att_obj["absentees"] = absentees[i];
@SalithaUCSC
SalithaUCSC / loader.css
Created October 3, 2018 16:16
Css styling for a loader
/* <div class="loader"></div> */
.loader {
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 9999;
background: url('img/loader.gif') 50% 50% no-repeat rgb(249, 249, 249);
opacity: .8;
@SalithaUCSC
SalithaUCSC / stackedBarChart.js
Last active October 6, 2018 08:20
D3 JS function to draw a Stacked Bar Chart
drawChart(data){
var data = [
{class: "A", absentees: 10, presentees: 30},
{class: "B", absentees: 5, presentees: 35},
{class: "C", absentees: 15, presentees: 40},
];
var chart = document.getElementById("chart");
@SalithaUCSC
SalithaUCSC / bmi-calculator-index.html
Last active October 23, 2018 17:21
INDEX file in BMI Calculator project
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
@SalithaUCSC
SalithaUCSC / bmi-calculator-app.css
Created October 23, 2018 17:30
App.css in BMI Calculator project
body {
font-family: 'Lato', sans-serif;
}
.bmiPng {
width: 100px;
height: 100px;
}
.App {
@SalithaUCSC
SalithaUCSC / bmi-calculator-app.js
Created October 23, 2018 18:00
App.js file in BMI Calculator project
import React, { Component } from 'react';
import './App.css';
import BmiCalculator from './components/BmiCalculator';
class App extends Component {
constructor(){
super();
this.state = {
title: "BMI Calculator"
@SalithaUCSC
SalithaUCSC / BmiCalculator.js
Last active October 23, 2018 18:10
BmiCalculator Component
import React, { Component } from 'react'
import Form from './Form';
import Navbar from './Navbar';
import bmiPng from '../assets/bmi.png';
class BmiCalculator extends Component {
constructor(props){
super(props);
}