Skip to content

Instantly share code, notes, and snippets.

View sagars01's full-sized avatar

Sagar sagars01

View GitHub Profile
@sagars01
sagars01 / chatbot.py
Last active January 8, 2024 17:46
AI Chatbot using LangChain, OpenAI and Custom Data ( Excel )
# -*- coding: utf-8 -*-
"""UniSyd_LangChain_Faiss.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1STqfsfZoWWhL1lUTyo0QJVCidXDvd7B4
# DEPENDENCIES
"""
@sagars01
sagars01 / sqlnosql.md
Created June 12, 2023 19:03
DB Mindmap
mindmap
  root(DB)
    SQL("SQL Databases")
      SQLDB("Examples: MySQL, PostgreSQL, Oracle")
      SQLDESC("Use Structured Query Language")
      SQLSTORAGE("Data Stored in Tables")
      SQLUSE("Best for Complex Queries and Transactions")
 NOSQL("NoSQL Databases")
@sagars01
sagars01 / tts.js
Created November 11, 2020 04:42
12 Liner - Text to Speech using NodeJS on Mac | No external libraries
const { exec } = require('child_process');
const text = `Often we need to check a sequence of conditions and do something when one of them is true. For example, say you’re ordering Chinese food and you’re choosing what to eat. Your favorite Chinese dish is lemon chicken, so you’ll have that if it’s on the menu. If it’s not, you’ll have beef with black bean sauce. If that’s not on the menu, you’ll have sweet and sour pork. In the rare case that none of those options is available, you’ll have egg fried rice, because you know all the Chinese restaurants you go to will have that.`
exec(`say -o hello.aiff '${text}'`, (error, stdout, stderr) => {
if (error) {
console.log(`error ${error}`);
}
if (stderr) {
@sagars01
sagars01 / duplicateChars.js
Last active June 12, 2019 14:34
Find duplicate characters in string in O(n) complexity
function findDuplicate(str) {
let charArr = populate(256);
let splitStr = str.split('');
for(let i = 0; i < splitStr.length; i++) {
let charCode = splitStr[i].charCodeAt();
charArr[charCode]++;
}
return findDuplicates(charArr);
}
function askPolitely(sentence){
let comparator = "please?";
let _sentenceBreakDown = sentence.split(' ');
const lastWord = _sentenceBreakDown[_sentenceBreakDown.length - 1];
if( lastWord != comparator) {
_sentenceBreakDown.pop();
let clearWord = wordGen(lastWord, '?');
_sentenceBreakDown.push(clearWord);
_sentenceBreakDown.push(comparator);
let z = _sentenceBreakDown.join(" ");
function x(n) {
if(n !== 0 && n > 0){
if(n == 1) {
console.log(n);
return;
}
if(n % 2 == 1) {
console.log(n);
}
x(n-1);
@sagars01
sagars01 / treeSum
Created October 26, 2017 13:07
Simple Binary Tree calculation
var parent = {
left : {
node1 : 10,
node2 : 30
},
right : [
{
leaf1 : 20 ,
leaf1a: [
@sagars01
sagars01 / For Loop Indention
Last active July 19, 2017 18:11
For Loop Problem for Pushing data in Array of Objects
function convertAddTypeBaseLine(data,addType){
var arr = [],arr2=[];
for(var j in addType){
data.forEach(function(data,key) {
var obj={};
for(let [key, value] of Object.entries(data)){
obj[key] = value;
}
obj.type = addType[j];
arr.push(obj);
@sagars01
sagars01 / duplicateNumberinArray.js
Created May 17, 2017 13:45
How to find duplicate elements in array using javascript.
var array1 = [1,1,3333, 333,3333, 2 ,2, 3, 4];
var temp = [];
for(var i = 0; i < array1.length; i++){
if(temp.indexOf(array1[i]) === -1) {
temp.push(array1[i]);
}else {
console.log("Duplicate Value Found!");
break;
}
}
@sagars01
sagars01 / abstractioninJS.js
Created May 3, 2017 19:47
Implementing abstraction in JavaScript
var absShape = function() {
//this.typeOfShape = "none";
throw new Error("Cannot create instance of this Class");
}
//var circle = new absShape(); O/P : Error: Cannot create instance of this Class
absShape.prototype.drawShape = function() {
return "Shape Drawn is " + this.shapeName;
}
var Circle = function(shapeName) {
this.shapeName = shapeName;