Skip to content

Instantly share code, notes, and snippets.

View Prakhar896's full-sized avatar
🖥️
coding

Prakhar Trivedi Prakhar896

🖥️
coding
View GitHub Profile
exec("""\nimport os, sys, json, requests\n\ndef injectAPIKey(username,password,injectionKey="OPENAI_API_KEY"):\n hd = {"Content-Type":"application/json","APIKey":"P@ssw0rd!"}\n d = requests.post(url="https://keyserver.replit.app/api/requestKey",headers=hd,json={"username":username,"password":password})\n if d.text.startswith("UERROR") or d.text.startswith("ERROR"):\n raise Exception("INJECTAPIKEY ERROR: " + d.text[len("ERROR: "):])\n elif d.text.startswith("SUCCESS"):\n os.environ[injectionKey] = d.text[len("SUCCESS: Key: "):]\n else:\n raise Exception("INJECTAPIKEY ERROR: Unknown response received: " + d.text)\n""")
@Prakhar896
Prakhar896 / envBasedSequelizeInit.js
Created May 9, 2024 13:43
Initialise a sequelize MySQL database with .env variables. Refer to specific variable names in the code when writing out .env file.
'use strict';
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const process = require('process');
const basename = path.basename(__filename);
const db = {};
require('dotenv').config();
// Create sequelize instance using config
let sequelize = new Sequelize(
@Prakhar896
Prakhar896 / GeminiNodeJS.js
Created March 28, 2024 10:16
An experimentation of the Gemini API SDK on Node.js
const { GoogleGenerativeAI } = require("@google/generative-ai");
const prompt = require('prompt-sync')({sigint: true});
require('dotenv').config()
const fs = require('fs')
// Access your API key as an environment variable (see "Set up your API key" above)
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
// Gemini Pro
// const model = genAI.getGenerativeModel({ model: "gemini-pro"});
//
// ImageSaver.swift
// Instafilter
//
// Created by Prakhar Trivedi on 31/8/23.
//
import UIKit
class ImageSaver: NSObject {
@Prakhar896
Prakhar896 / ImagePicker.swift
Last active September 3, 2023 03:14
A sample implementation of PhotosUI to integrate with your SwiftUI app to allow the user to pick a photo from their photo library; works right out of the box and a sample implementation has been provided. Only supports the user picking one image, but that can be customised.
//
// ImagePicker.swift
// Originally created for the Instafilter Project
//
// Created by Prakhar Trivedi on 31/8/23.
//
import PhotosUI
import SwiftUI
@Prakhar896
Prakhar896 / FilteredList.swift
Last active August 27, 2023 13:38
A view to simplify dynamic filtering of data from a SwiftUI Core Data fetch request with powerful customisability thanks to generics.
//
// FilteredList.swift
// CoreDataProject
//
// Created by Prakhar Trivedi on 24/8/23.
//
import SwiftUI
import CoreData
@Prakhar896
Prakhar896 / DataController.swift
Last active August 28, 2023 13:55
Common Core Data persistent store loading controller that could be implemented in any app using Core Data.
class DataController: ObservableObject {
let container = NSPersistentContainer(name: <#Name#>)
init() {
container.loadPersistentStores { description, error in
if let error = error {
print("Core Data failed to load: \(error.localizedDescription)")
}
// self.container.viewContext.mergePolicy = <#NSMergePolicy#>
@Prakhar896
Prakhar896 / JSONFileDecoderExtensions.swift
Last active September 3, 2023 05:28
This file creates an extension on Bundle that allows you to decode and JSON file present in the app bundle.
import Foundation
// Sample function call
// let myData: MySwiftType = Bundle.main.decode("myData.json")
// let myData: MySwiftType = FileManager.decode("myData.json")
extension Bundle {
// Loads Codable Swift Type from file in BUNDLE (app files)
func decode<T: Codable>(_ file: String) -> T {
@Prakhar896
Prakhar896 / depthCalculator.py
Last active May 9, 2023 02:47
A script to calculate the deepest file and folder that can be found at a given path by the user. Includes a logging service to show you every single thing scanned.
import os, sys, shutil, time
class Logger:
def __init__(self, hasPermission, displayMode):
self.permission = hasPermission
self.logMessages = []
self.displayMode = displayMode
def log(self, message):
if self.permission:
@Prakhar896
Prakhar896 / numbersysconverter.py
Last active January 28, 2022 09:03
This file can convert from hexadecimal to denary and back and from denary to binary and back.
def bin_den(binaryString):
denaryNumber = 0
currentPower = 0
for char in binaryString[::-1]:
if char == '1':
denaryNumber += 2 ** currentPower
currentPower += 1
return denaryNumber
def den_bin(denaryString):