Skip to content

Instantly share code, notes, and snippets.

View chirag-shinde's full-sized avatar
💾
learning, unlearning & relearning!

Chirag Shinde chirag-shinde

💾
learning, unlearning & relearning!
View GitHub Profile
import chokidar from 'chokidar';
import fs from 'fs';
import path from 'path';
import dotenv from 'dotenv';
dotenv.config();
const OPENROUTER_API_KEY = process.env.OPENROUTER_API_KEY;
const PROMPTS = [
def selection_sort(arr):
for i in range(len(arr)):
min_element_index = i
for j in range(i + 1, len(arr)):
if arr[j] < arr[min_element_index]:
min_element_index = j
arr[i], arr[min_element_index] = arr[min_element_index], arr[i]
def quick_sort(arr,start, end):
if start < end:
pivot = partition(arr, start, end)
quick_sort(arr, start, pivot - 1)
quick_sort(arr, pivot + 1, end)
def partition(arr, start, end):
element = arr[start]
i = start
for j in range(start + 1, end):
def merge_sort(arr):
if len(arr) > 1:
mid = len(arr) // 2
left = arr[:mid]
right = arr[mid:]
merge_sort(left)
merge_sort(right)
merge(arr,left,right)
def merge(arr, left, right):
def insertion_sort(list: [int]) -> [int]:
for i in range(1, len(list)):
element = list[i]
j = i - 1
while j >= 0 and element < list[j]:
list[j + 1] = list[j]
j -= 1
list[j + 1] = element
return list
class Solution:
def sum_of_squares(self, n: int) -> int:
total = 0
while n > 0:
total += (n % 10) ** 2
n = int(n / 10)
return total
def isHappy(self, n: int) -> bool:
fast = self.sum_of_squares(n)
class Solution:
def sum_of_squares(self, n: int) -> int:
total = 0
while n > 0:
total += (n % 10) ** 2
n = int(n / 10)
return total
def isHappy(self, n: int) -> bool:
repeat_numbers = set()
class Solution:
def singleNumber(self, nums: List[int]) -> int:
nums_set = set()
for num in nums:
if num in nums_set:
nums_set.remove(num)
else:
nums_set.add(num)
return nums_set.pop()
class Solution:
def singleNumber(self, nums: List[int]) -> int:
return reduce( lambda x, y: x ^ y, nums)
@chirag-shinde
chirag-shinde / uploadMethodTwo.php
Last active April 21, 2021 07:39
PHP Script to Upload CSV to MongoDB. Method Two of Two.
<!-- MongoDB has a command named mongoimport which can be used to directly upload a CSV file into a particular collection of
a database with the first line of the csv as the keys and the following rest of the csv as the values for the respective keys
The format of mongoimport is as folllows
"mongoimport --db database_name --collection collection_name --file csv_file_name --type csv"
now we can use variables to store our database and collection's name.
we upload the file to get the filename and it's path and then simple substitute the database_name and collection_name etc