Skip to content

Instantly share code, notes, and snippets.

View BharatKalluri's full-sized avatar
🎯
Focusing

Bharat Kalluri BharatKalluri

🎯
Focusing
View GitHub Profile
@BharatKalluri
BharatKalluri / upload.ts
Created October 21, 2021 20:41
Nextjs route to upload files to s3
import {NextApiRequest, NextApiResponse} from "next";
import {Photo} from '@prisma/client'
import Busboy from "busboy";
import {PutObjectCommand, S3Client} from "@aws-sdk/client-s3";
import crypto from "crypto";
import {S3_BUCKET} from "../../constants";
const client = new S3Client({});
export async function storePhoto(ctx: { fileBuffer: Buffer, mimeType: string }) {
@BharatKalluri
BharatKalluri / totp.py
Created October 24, 2021 13:23
TOTP implementation in python
import base64
import hashlib
import hmac
import math
import time
def dynamic_truncation(raw_key: hmac.HMAC, length: int) -> str:
hex_digest: str = raw_key.hexdigest()
int_repr: int = int(hex_digest, base=16)
@BharatKalluri
BharatKalluri / main.py
Last active December 9, 2021 18:42
Script to run through a zip files containing ISBN 13 file named covers for OpenLibrary
import datetime
import os
import sys
import zipfile
from zipfile import ZipFile, ZipInfo
from olclient import OpenLibrary, config
from sqlmodel import Field, SQLModel, create_engine, Session, select
import logging
@BharatKalluri
BharatKalluri / auto_mute_spotify_profile.sh
Last active February 5, 2022 19:02
Snippets on medium
# .profile
# Mute spotify on ad
while sleep 1; do mute_ad_spotify; done &
@BharatKalluri
BharatKalluri / vala-101.vala
Last active December 29, 2021 18:42
Vala 101
class Vala.Basics : GLib.Object {
public static void post_request() {
var soupSession = new Soup.Session ();
var soupMessage = new Soup.Message("POST", "https://reqres.in/api/users");
var body = "{\"name\":\"morpheus\"}";
soupMessage.set_request(
"application/json",
Soup.MemoryUse.COPY,
body.data
@BharatKalluri
BharatKalluri / mv_and_rename_shots_hash.py
Last active March 22, 2022 13:49
Renames files with their hash for picture management
#!/usr/bin/env python3
import hashlib
import logging
import os.path
import shutil
import sys
from pathlib import Path
from typing import List
@BharatKalluri
BharatKalluri / cal_parser.py
Last active January 29, 2022 14:40
Meeting stats from calendar
import datetime
from datetime import timedelta
from functools import reduce
from typing import TextIO
import icalendar
ical_contents_raw: TextIO = open('/Users/bharatkalluri/Downloads/bharat@refyne.co.in.ics', 'r')
ical_contents: str = ical_contents_raw.read()
work_cal = icalendar.Calendar.from_ical(ical_contents)
@BharatKalluri
BharatKalluri / config.py
Created August 11, 2022 10:09
HDFC bank statement importer for Beancount
import sys
from typing import List
from beancount.core.number import D
from beancount.ingest import importer
from beancount.core import amount, flags
from beancount.core.data import Posting, Transaction, new_metadata
from smart_importer import apply_hooks
from smart_importer.detector import DuplicateDetector
@BharatKalluri
BharatKalluri / blockchain.ipynb
Last active November 9, 2022 06:02
An simple implementation of blockchain using python
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@BharatKalluri
BharatKalluri / zostel.py
Created January 22, 2023 17:05
Find all available dorms across zostels in a time range
import requests
# find these from avalibility get request for your session
TOKEN = "Bearer "
CLIENT_APP_ID = ""
CLIENT_USER_ID = ""
# input dates here
check_in = "2023-01-25"
check_out = "2023-01-29"