Skip to content

Instantly share code, notes, and snippets.

View shivendrasoni's full-sized avatar
💭
Grinding

Shivendra Soni shivendrasoni

💭
Grinding
View GitHub Profile
@shivendrasoni
shivendrasoni / sqlite_query_optimiser_agent.py
Created July 29, 2024 20:22
A Langgraph Agent to optimise SQL Lite database queries by observing a query log.
###
# It does not implement or force how you want to generate the logs
# It Assumes that the query logs are in a CSV file of format:
# timestamp,query,execution_time
# 2023-07-30 14:30:15,SELECT * FROM users WHERE age > 30,0.123456
# 2023-07-30 14:30:16,INSERT INTO orders (user_id, product_id, quantity) VALUES (1, 5, 2),0.054321
###
import os
from typing import Dict, List
from langgraph.graph import Graph, StateGraph
import json
import dateutil.parser
from datetime import date
import numpy as np
import pandas as pd
import dateutil.parser
import streamlit as st
class Message:
def __init__(self, content):
self.content = content
self.read_by = set()
class Topic:
def __init__(self, name):
self.name = name
self.messages = []
self.consumer_groups = {}
@shivendrasoni
shivendrasoni / CardGame.py
Last active August 27, 2018 10:14
An object oriented implementation of a card deck (configurable to different kinds of cards) and a card game simulation
import random
class Card(object):
def __init__(self, suit, rank):
self.suit = suit
self.rank = rank[0]
self.name = rank[1]
@shivendrasoni
shivendrasoni / flatten.js
Created July 20, 2017 14:05
An array of arbitrarily nested arrays of integers into a flat array of integers
/*
Deep Flatten a nested array.
Reduce if the child is an array, else concattenate the element to the the parent array.
*/
var deepFlatten = (r, a) => Array.isArray(a) ? a.reduce(deepFlatten, r) : r.concat(a)
@shivendrasoni
shivendrasoni / roles_invesitgation.md
Created January 6, 2016 21:35 — forked from facultymatt/roles_invesitgation.md
Roles and permissions system for Nodejs
@shivendrasoni
shivendrasoni / setup.sh
Last active October 13, 2015 16:10
Build Setup bash
# IMPORTANT SHIT : A cat will die unless you read this.
# generate your ssh public key and add it to gitlab, github and your to your body as a tattoo
# ssh-keygen // to Generate ssh key
# cat ~/.ssh/id_rsa.pub // to print it to console
# fucking copy the above key and add it to ur git repo etc.
#
# sudo apt-get install autoconf automake autoheader -y;
sudo apt-get install build-essential -y;
@shivendrasoni
shivendrasoni / Natural Sort
Created September 3, 2014 08:50
A natural sort comparator function to be used with Javascript's sort API.
function naturalSort(a, b) {
var NUMBER_GROUPS = /(-?\d*\.?\d+)/g;
var aa = String(a).split(NUMBER_GROUPS),
bb = String(b).split(NUMBER_GROUPS),
min = Math.min(aa.length, bb.length);
for (var i = 0; i < min; i++) {
var x = parseFloat(aa[i]) || aa[i].toLowerCase(),
y = parseFloat(bb[i]) || bb[i].toLowerCase();
if (x < y) return -1;