Skip to content

Instantly share code, notes, and snippets.

View obbap1's full-sized avatar

Obba Paschal obbap1

View GitHub Profile
//Initialize redis and create a client.
const redis = require('redis');
const client = redis.createClient();
//Error handler
client.on('error',(err)=>{
console.log("error",err);
return err;
});
//Check if errors occured while connecting to the db.
const initializationOptions = {
@obbap1
obbap1 / crud.js
Created November 24, 2018 02:35
const fs = require('fs');
const path = require('path');
const { promisify } = require("util");
const readFile = promisify(fs.readFile);
const crud = {};
crud.baseDir = path.join(__dirname,'./database');
//Write data to a file
const {ApolloServer, gql} = require('apollo-server')
const typeDefs = gql`
type User {
email: String!
password: String!
}
type Mutation {
imapMutation(email: String!, password: String!): User!
}
`
const typeDefs = gql`
scalar Date
# Make a type user
type User {
email: String!
password: String!
data: [Graph!]
}
const newCategory = {
Thumbnail: undefined,
checkFile (category, file) {
file ?
category.categoryThumbnail = {name: file.public_id, url: file.url}
: category.categoryThumbnail = null
this.Thumbnail = category.categoryThumbnail;
return this;
const { expect } = require('chai')
const createCategoryFactory = require('../create-category')
const ProductCategory = require('./mocks/product-category.mock')
const req = require('./mocks/req.mock')
const res = require('./mocks/res.mock')
describe('create-category', () => {
const createCategory = createCategoryFactory({ ProductCategory })
beforeEach(() => {
@obbap1
obbap1 / solution.js
Last active January 14, 2022 21:41
Hacker rank's 'Stock Open Close Price' Solution with JS
const https = require("https");
const monthNames = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
/******************** HELPER FUNCTION **********************/
//Filter array for any distinct values --- STACKOVERFLOW
function isDistinct(array) {
return new Set(array).size === array.length;
}
// Use combination sum to get all the possible combinations
function combinationSum(candidates, target) {
var result = [];
interface IEdge {
key: string
from: string
to: string
}
interface IVertex {
key: string
label: string
}
let str = "i am a boy and i am happy to be in your midst"
const final = {}
str.split(" ").map((s, index, arr) => {
// remove the commas
// make lowercase
// console.log({s})
if(s == "am") {
if(!final[s]) {