Skip to content

Instantly share code, notes, and snippets.

View onejohi's full-sized avatar
🎯
Focusing

onejohi onejohi

🎯
Focusing
View GitHub Profile
# This is a custom made Python function/method I made that accepts an array value and calculates the variance
def variance(array_value):
sum = 0
for i in array_value:
sum += i
mean = sum / len(array_value)
difference_value = 0
for j in array_value:
const arrayOfNumbers = ['BOB778','KEK7899','FOR4442','KIMP889'];
const numberValues = arrayOfNumbers.map(item => item.match(/\d+/)[0]);
const sumOfNumbers = numberValues.reduce((total, num) => Number(total) + Number(num));
// sumOfNumbers = 14008 [778 + 7899 + 4442 + 889]
// an absctract representation
class Person {
constructor(name,email) {
this.name = name
this.email = email
}
// things a person can do (functions/methods within a class)
sayName() return `My name is ${this.name}`;
emailAddress() return this.email;
const express = require('express');
const router = express.Router();
const { verifyJWToken } = require("../utils/authUtils");
const OrderController = require("../controllers/order.controller");
router.post("/remove", verifyJWToken, OrderController.deleteOrder);
router.post("/confirm", verifyJWToken, OrderController.confirmDelivery);
router.post("/cancel", verifyJWToken, OrderController.cancelDelivery);
const { sign, verify } = require("jsonwebtoken");
module.exports = {
verifyJWToken(req, res, next) {
if (req.headers.authorization) {
const token = req.headers.authorization.split(" ")[1];
verify(token, 'secretword', { complete: true }, (error, decoded) => {
if (error) { res.json({ ok: false, error }) }
if (decoded ) { next() }
});
@onejohi
onejohi / app.js
Last active September 18, 2019 19:35
const express = require('express')
const BusBoy = require('busboy')
const path = require('path')
const os = require('os')
const fs = require('fs')
const app = express()
app.post('/', (req, res) => {
const busboy = new BusBody({ headers: req.headers })
mounted() {
// call methods when component is done "mounting" :wink:
this.getUserLocation();
this.trackUserLocation();
},
methods: {
getUserLocation() {
// get user position
window.navigator.geolocation.getCurrentPosition((position) => {
const { latitude, longitude } = position.coords;
import { Component } from '@angular/core';
@Component({
selector: 'app-login',
templateUrl: 'app-login.html',
styleUrls: ['styles.css'],
})
export class AppLogin {
constructor() { }
import { Component, OnInit } from '@angular/core';
import StateService from '../services/state.service.ts';
@Component({
selector: 'app-change-state',
template: `
<div>
<div> {{username }} </div>
<input [(ngModel)]="username" placeholder="enter username" />
<button (click)="updateUsername()"></button>
import Injectable from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
@Injectable()
export class StateService {
private usernameSource = new BehaviorSubject<string>('Onejohi Tony');
username = this.usernameSource.asObservable()
constructor() { }