Skip to content

Instantly share code, notes, and snippets.

@saravr
saravr / mcp_openai.py
Created April 13, 2025 19:23
Sample MCP OpenAI call
#
# Courtesy: Perplexity.AI
#
import json
from openai import OpenAI
class AutoMCPClient:
def __init__(self, api_key, model="gpt-4-0613"):
self.client = OpenAI(api_key=api_key)
@saravr
saravr / http_server.js
Last active March 28, 2025 00:46
HTTP server with delay option
const http = require('http');
const fs = require('fs');
const path = require('path');
const url = require('url');
// Parse command-line arguments
const args = process.argv.slice(2);
const baseDirectory = args[0] || '.'; // Default to current directory
const portArg = args.find(arg => arg.startsWith('--port='));
const delayArg = args.find(arg => arg.startsWith('--delay='));
@saravr
saravr / compose-starter.txt
Last active November 16, 2024 19:38
Compose starter template
Typical additions on top of the Android Studio Jetpack Compose template.
Root gradle
===========
plugins {
id("com.google.dagger.hilt.android") version "2.51.1" apply false
}
Module gradle
@saravr
saravr / apps.tips
Created September 27, 2024 04:19
apps
# Export firebase firestore to json
npx -p node-firestore-import-export firestore-export -a credentials.json -b backup.json
# Import firebase firestore from json
npx -p node-firestore-import-export firestore-import -a credentials.json -b backup.json
@saravr
saravr / watermark.sh
Created September 25, 2024 05:39
Add watermark to PDF files
# usage: watermark.sh <pdf file name without extension>
#
magick $1.pdf \
-gravity Center \
-pointsize 40 \
-fill 'rgba(169, 169, 169, 0.5)' \
-draw "rotate -45 text 0,0 'SAMPLE WATERMARK'" \
-alpha on -background none -compose over \
$1-WM.pdf
@saravr
saravr / misc.tips
Last active September 29, 2024 22:22
Misc Tips
video -> gif:
ffmpeg -i ripplefix.mp4 -pix_fmt rgb8 -r 10 output.gif && gifsicle -O3 output.gif -o output.gif
mongodb
=======
mongoexport --uri="mongodb://localhost:27017/your_database" --collection=challenges --out=challenges.json --jsonArray
@saravr
saravr / git.tips
Created September 25, 2024 05:33
GIT Tips
- Multiple git accounts
config:
Host bitbucket.org
Hostname bitbucket.org
IdentityFile ~/.ssh/id_bb
Host github.com-personal
Hostname github.com
@saravr
saravr / android.tips
Last active January 25, 2025 13:31
android.tips
Increase adb buffer size
========================
adb logcat -b main -G 16M
adb logcat -g
Decode obfuscated trace
=======================
~/Library/Android/sdk/tools/proguard/bin/retrace.sh proguard.map <stacktracefile>
Doze mode
plugins {
id 'com.android.library'
id 'maven-publish'
}
group = "com.example"
version = "1.0.0"
android {
namespace 'com.example.lib0'
compileSdk 32
@saravr
saravr / gist:c6999e5cc2a302b5c7ada0cd464b7baa
Created September 30, 2021 19:27
Date Utils in Kotlin
import android.text.format.DateUtils
fun getDurationString(secondsElapsed: Long): String {
val hours = secondsElapsed / 3600
val minutes = (secondsElapsed % 3600) / 60
val seconds = secondsElapsed % 60
return if (hours > 0)
String.format("%02d:%02d:%02d", hours, minutes, seconds)
else
String.format("%02d:%02d", minutes, seconds)