Skip to content

Instantly share code, notes, and snippets.

View EteimZ's full-sized avatar

Youdiowei Eteimorde EteimZ

View GitHub Profile
@EteimZ
EteimZ / time-event.js
Created February 12, 2023 11:24
A time class built with EventEmitter class.
const EventEmitter = require('node:events');
class Timer extends EventEmitter {
constructor(){
super();
this.intervalId = null;
}
start(){
@EteimZ
EteimZ / counterEvent.js
Created February 12, 2023 00:52
Exploring events with a counter class
const EventEmitter = require('node:events');
class Counter extends EventEmitter {
count = 0
increment(){
this.count++;
}
decrement(){
@EteimZ
EteimZ / curry.js
Created January 31, 2023 07:58
Basic explanation of currying.
// create a curried function
const introSelf = lastName => firstName => console.log(`My name is ${firstName} ${lastName}`)
// use curried function
introSelf("Youdiowei")("Eteimorde")
// Output: My name is Eteimorde Youdiowei
// partially apply the curried function to create a new one
const introDoe = introSelf("Doe")
@EteimZ
EteimZ / Time.cpp
Created January 16, 2023 22:16
Demonstrating the dangerous effect of returning a reference from a class. Gotten from the book C how to program.
#include "Time.h"
Time::Time(int hr, int min, int sec){
setTime(hr, min, sec);
}
void Time::setTime(int h, int m, int s){
hour = ( h >= 0 && h < 24 ) ? h : 0;
minute = ( m >= 0 && m < 60 ) ? m : 0;
second = ( s >= 0 && s < 60 ) ? s : 0;
@EteimZ
EteimZ / static-fib.cpp
Created January 9, 2023 22:44
Fib implemented with the static keyword in C++
#include <iostream>
using namespace std;
void fib(){
static int a = 0;
static int b = 1;
static int c;
cout << a << endl;
c = a;
@EteimZ
EteimZ / Time.cpp
Created January 8, 2023 21:19
Example using default constructors and getters and setters in cpp. Example is gotten from the book C How to Program.
// Member-function definition for class time
#include <iostream>
using std::cout;
#include <iomanip>
using std::setfill;
using std::setw;
#include "Time.h"
@EteimZ
EteimZ / SalesPerson.cpp
Last active January 7, 2023 02:10
An example demonstrating the use of utility functions within classes in OOP. Gotten from the book C How to Program.
// Implementation for class SalesPerson
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::fixed;
#include <iomanip>
using std::setprecision;
@EteimZ
EteimZ / Count.cpp
Created January 7, 2023 00:55
Counter example from the book C how to program.
// Implementation file for Count class
#include <iostream>
#include "Count.h"
using std::cout;
using std::endl;
// set value of private data member x
void Count::setX(int value){
x = value;
@EteimZ
EteimZ / Time.cpp
Created January 4, 2023 21:47
Time class implementation in cpp gotten from the book C How to program.
// Member-function definitions for class Time
#include <iostream>
using std::cout;
#include <iomanip>
using std::setfill;
using std::setw;
#include "Time.h" // include definition of class Time from Time.h
@EteimZ
EteimZ / GradeBook.cpp
Created January 3, 2023 22:59
GradeBook OOP example from the Book C How to Program
// GradeBook Implementation
#include <iostream>
using std::cout;
using std::endl;
#include "GradeBook.h" // include interface
// constructor implementation
GradeBook::GradeBook(string name){