Skip to content

Instantly share code, notes, and snippets.

View ChukwuEmekaAjah's full-sized avatar
💭
Building

Chukwuemeka Ajah ChukwuEmekaAjah

💭
Building
View GitHub Profile
let timeNow = new Date();
let currentHour = timeNow.getHours();
let count = 1;
let idk = null
function greet(){
if (count == 10){
clearInterval(idk);
}
if ((5 <= currentHour) && (currentHour <= 10)){
@ChukwuEmekaAjah
ChukwuEmekaAjah / ago.js
Created August 28, 2022 20:01
Return how long ago an event occurred with respect to current time.
const pluralize = function (value){
return Math.floor(value) > 1 ? 's' : '';
}
function ago(date){
const now = Math.floor(Date.now()/1000)
const time = new Date(date)
if(isNaN(time.getTime())){
throw new Error(`Passed in date ${date} is not a valid date`)
}
@ChukwuEmekaAjah
ChukwuEmekaAjah / timestampdb.js
Created May 30, 2023 22:55
This is an implementation of timestamp key-value store that allows historical record of values inserted for a key in a db. This implementation uses a sorted set of timestamps to make sure that the db meets its constraints.
class TimeStampDB{
constructor (){
this.db = {}
}
set(key, timestamp, value){
this.db[key] = this.db[key] || {}
this.db[key][timestamp] = value
this.db[key]['timestamps'] = this.db[key]['timestamps'] || []
// find insert position for sorted set of timestamps array
@ChukwuEmekaAjah
ChukwuEmekaAjah / ignored_files.ts
Created July 16, 2023 22:23
A basic implementation of how files to be ignored in 'ignore' files are found and ignored
import * as path from "path"
import * as fs from "fs"
// find all files that match the corresponding splitted directory component
// find all files and folders that match the regular expression of the corresponding path
// filter out all unmatched files/folders from the list based on splitted path
function getIgnoredFiles(ignorePath: string) :string[]{
const allFiles = walk(process.cwd(), [], {})
const regex = buildRegex(ignorePath)