Skip to content

Instantly share code, notes, and snippets.

View iKnowJavaScript's full-sized avatar
🎯
Focusing

Victor Omolayo iKnowJavaScript

🎯
Focusing
View GitHub Profile
@iKnowJavaScript
iKnowJavaScript / User.js
Last active April 29, 2019 08:44
Demo app
// User constructor
function User(name, email) {
this.name = name;
this.email = email;
this.isAdmin = false;
}
// Note: this "{}" represent the Constructor itself
// User constructor
function User(name, email) {
this.name = name;
this.email = email;
this.isAdmin = false;
}
// We can now add methods to its prototype like so...
User.prototype.postComment = function(message) {
//add Post implementation here
function Admin(name, email) {
User.call(this, name, email);
this.isAdmin = true;
}
Admin.prototype = Object.create(User.prototype);
Admin.prototype.constructor = Admin;
// we can now add methods and props to Admin Prototype
Admin.prototype.deleteAllComment = function() {
@iKnowJavaScript
iKnowJavaScript / logic.js
Last active May 2, 2019 01:43
Getting started with jest testing
function sum(arr) {
let total = 0;
for(let i = 0; i < arr.length; i++) {
total += arr[i];
}
return total;
}
const numbers = [1,2,3,4,5]
sum(numbers); //15
@iKnowJavaScript
iKnowJavaScript / logic.test.js
Last active May 2, 2019 01:49
Test file for logic.js
// reguire the real file to be tested
const { sum, doubleNumber} = require("./logic.js") //use correct path
describe("Sum function should return the sum of all the numbers in an array", function() {
it("Should return 4 for [1,2,1]", function() {
expect(sum([1,2,1])).toEqual(4)
})
it("Should return 10 for [1,2,3,4,5]", function() {
expect(sum([1,2,3,4,5])).toEqual(15)
})
// one liner
const sum = (arr) => arr.reduce((acc, item) => acc + item, 0);
const doubleNumber = (arr) => arr.map((item) =>item * 2)
//dont forget to export
module.exports = { sum, doubleNumber }
@iKnowJavaScript
iKnowJavaScript / cloudSettings
Last active February 2, 2021 03:47 — forked from bradtraversy/js_linked_list.js
JS Linked List Class
{"lastUpload":"2019-09-23T19:23:17.433Z","extensionVersion":"v3.4.3"}
@iKnowJavaScript
iKnowJavaScript / nodejs-rfid.js
Created February 25, 2020 10:19 — forked from basham/nodejs-rfid.js
Use NodeJS to read RFID ids through the USB serial stream.
/*
DESCRIPTION
-----------
Use NodeJS to read RFID ids through the USB serial stream. Code derived from this forum:
http://groups.google.com/group/nodejs/browse_thread/thread/e2b071b6a70a6eb1/086ec7fcb5036699
CODE REPOSITORY
---------------
https://gist.github.com/806605
@iKnowJavaScript
iKnowJavaScript / spinner-style.ts
Created May 7, 2020 16:33
Web component spinner button
export const submitSpinnerStyle = css`
.lds-ring {
width: 40px;
height: 40px;
}
.lds-ring div {
box-sizing: border-box;
display: block;
position: absolute;
width: 25px;
@iKnowJavaScript
iKnowJavaScript / opt-style.ts
Created June 22, 2020 10:09
OTP with web component
import { css, CSSResult } from "lit-element";
export const twoFactorStyles: CSSResult = css`
:host {
display: block;
font-family: var(--base-font, var(--base-fallback-color));
}
.submit-btn {
position: relative;