Skip to content

Instantly share code, notes, and snippets.

View colibie's full-sized avatar
💭
You're awesome!

Chidera colibie

💭
You're awesome!
View GitHub Profile
@colibie
colibie / setup.js
Created December 10, 2019 12:02
A gist that contains the setup configuration for text anaytics api
const key_var = 'TEXT_ANALYTICS_SUBSCRIPTION_KEY';
if (!process.env[key_var] && !config[key_var]) {
throw new Error('please set/export the following environment variable: ' + key_var);
}
const subscription_key = process.env[key_var] || config[key_var];
const endpoint_var = 'TEXT_ANALYTICS_ENDPOINT';
if (!process.env[endpoint_var] && !config[endpoint_var]) {
throw new Error('please set/export the following environment variable: ' + endpoint_var);
}
@colibie
colibie / get_language.js
Created December 10, 2019 12:08
Holds function for detecting language using Azure Text Analytics
let get_language = async function (documents) {
let body = JSON.stringify(documents);
let url = endpoint + pathForLanguages;
let params = {
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': subscription_key
}
};
let data = await axios.default.post(url, body, params)
@colibie
colibie / index.js
Created December 10, 2019 12:16
Index file for text analytics using azure
//fetch wishes using axios
//for each wish, get data, perform language analysis on it
const axios = require('axios');
const {get_language, get_sentiments} = require('./cognitives');
module.exports = async function (context, req) {
let dataUrl = 'https://christmaswishes.azurewebsites.net/api/Wishes';
try {
let getData = await axios.default.get(dataUrl);
let data = getData.data;
@colibie
colibie / hello.js
Created April 19, 2020 14:09
A basic recursive function
function hello(i) {
if (i < 0) return; // base case
console.log(i);
hello(--i); // recursive call
}
hello(5) // output: 5 4 3 2 1 0
@colibie
colibie / iterativeHello.js
Created April 19, 2020 14:17
An iterative approach to hello.js
let i = 5; // I've chosen an arbitrary number
while (i > 0) {
console.log(i--);
}
// output: 5 4 3 2 1
@colibie
colibie / factorial.js
Last active April 19, 2020 14:24
An analysis of recursive factorial
function fact(n) {
if (n == 1) return n; // base case
return n * fact(n - 1); // recursive call
}
// fact(5) analysis - output = 120
fact(5)
5 * fact(4)
5 * (4 * fact(3))
@colibie
colibie / compareHello.js
Created April 19, 2020 14:27
A comparison of recursive hello.js and iterative hello.js
function hello(i) {
if (i < 0) return; // base case
console.log(i);
hello(--i); // recursive call
}
hello(5); // output: 5 4 3 2 1 0
function hello(i) {
hello(5)
hello(4)
hello(3)
hello(2)
hello(1)
hello(0)
hello(-1)
---
console.log(-1) // and other statements left
console.log(0) // and other statements left
/* eslint-disable no-console */
require('dotenv').config();
const cluster = require('cluster');
const jwt = require('jsonwebtoken');
const backgroundJobHandler = require('background_job_handler');
const app = require('./appREST');
const rpc = require('./appRPC');
const { DB } = require('./api/models');
@colibie
colibie / Digraph.js
Last active May 26, 2020 21:04
the data structure for a directed graph
export class Digraph { // exported so we can use it in topological sort
constructor(v) {
this.v = v; // initialize the number of vertices
this.e = 0; // and edges
this.adj = {}; // this object contains thevertices connected to each vertex.
}
addEdge(v, w) {
if (!adj[v]) adj[v] = []; // check if the vertex already exist, if not, created it
adj[v].push(w); // push the connecting edge vertex to its array of vertices