Skip to content

Instantly share code, notes, and snippets.

@mvark
mvark / WeatherUnionAPIsample.html
Created October 20, 2024 12:51
Simple code sample that fetches real-time weather details using Zomato's Weather Union public API. Read more - https://mvark.blogspot.com/2024/10/zomato-weather-union-real-time-weather.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weather NOW</title>
<style>
body {
margin: 0;
padding: 20px;
@mvark
mvark / WeatherUnionInfra.csv
Last active October 20, 2024 12:35
The CSV version of the latitude and longitude details of Zomato Weather Union weather stations extracted from this PDF file on 20-Oct-24 - https://b.zmtcdn.com/data/file_assets/65fa362da3aa560a92f0b8aeec0dfda31713163042.pdf
cityName localityName localityId latitude longitude device_type
Ahmedabad Paldi ZWL003133 22.994998 72.557474 2 - Rain gauge system
Ahmedabad Shahibag ZWL002302 23.058607 72.592212 2 - Rain gauge system
Ahmedabad Navrangpura ZWL003747 23.038426 72.558241 2 - Rain gauge system
Ahmedabad Chandkheda ZWL002503 23.117204 72.607123 2 - Rain gauge system
Ahmedabad Science-City Sola ZWL005979 23.087361 72.510289 2 - Rain gauge system
Ahmedabad Sector 16, Gandhinagar ZWL005987 23.216612 72.652543 2 - Rain gauge system
Ahmedabad Vastrapur ZWL001959 23.042513 72.524312 2 - Rain gauge system
Ahmedabad Prahlad Nagar ZWL007404 22.998074 72.515955 2 - Rain gauge system
Ahmedabad Nikol ZWL001898 23.077071 72.637566 2 - Rain gauge system
@mvark
mvark / ClassPerfChart.py
Last active September 17, 2024 15:38
Python script to generate charts showing class performance in different subjects by slabs after picking scores for each Subject from an Excel file
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
# Load the Excel file into a DataFrame
excel_file = r'C:\scores\scores.xlsx' # Replace with your Excel file path
sheet_name = 'Sheet1' # Replace with your sheet name if necessary
df = pd.read_excel(excel_file, sheet_name=sheet_name)
# Debug: Print column names
@mvark
mvark / Xterm.js
Created September 11, 2024 05:02
Bookmarklet to search a user's X timeline for a specified "term". Navigate to the user's profile page (x.com/user) and then click this bookmarklet. A pop-up window appears, asking for your search term. Returns the native X search results page, prepopulated with that term and limited to that user.
//bookmarklet by redditor @chickenandliver - https://www.reddit.com/r/bookmarklets/comments/1f7wk72/search_a_users_x_timeline_for_term/
javascript:(function(){
const term = prompt('Term?');
if (term) {
const username = new URL(location.href).pathname.split("/")[1];
window.location.href = `https://x.com/search?q=${encodeURIComponent(term)}%20(from%3A${encodeURIComponent(username)})&src=typed_query&f=live`;
}
})();
//Minified version -
@mvark
mvark / rattibha.js
Created September 7, 2024 18:43
Bookmarklet code that extracts the number in Twitter/X.com URL, constructs a Rattibha URL so that content can be read in an easy-to-read format (assuming it is already converted) and then redirects to that page
javascript:(function() {
var url = window.location.href;
var match = url.match(/\/status\/(\d+)/);
if (match && match[1]) {
var newUrl = "https://en.rattibha.com/thread/" + match[1];
window.location.href = newUrl;
} else {
alert("No matching thread ID found in the URL.");
}
})();
@mvark
mvark / JSON2CSV.py
Created September 1, 2024 03:52
Python script to convert a JSON file to CSV. This script loads JSON data from a file, converts it into a structured pandas DataFrame, and then saves that DataFrame as a CSV file. The main steps involve reading the JSON file, normalizing the JSON structure into a flat format (suitable for tabular data), and finally exporting that data into a CSV …
import json
import pandas as pd
# Load JSON data, specify the file name with JSON content
with open(r'C:\OFF\raw.json') as f:
data = json.load(f)
# Convert to DataFrame
df = pd.json_normalize(data['products'])
Old Name New Name Wikipedia
Allahabad or Ilahabad Prayagraj https://en.wikipedia.org/wiki/Prayagraj
Bangalore Bengaluru https://en.wikipedia.org/wiki/Bangalore
Bombay Mumbai https://en.wikipedia.org/wiki/Mumbai
Calcutta Kolkota https://en.wikipedia.org/wiki/Kolkata
Cape Comorin Kanyakumari or Kanniyakumari https://en.wikipedia.org/wiki/Kanyakumari
Cawnpore Kanpur https://en.wikipedia.org/wiki/Kanpur
Chicacole Srikakulam https://en.wikipedia.org/wiki/Srikakulam
Cochin Kochi https://en.wikipedia.org/wiki/Kozhikode
Conjeveram Kanchipuram https://en.wikipedia.org/wiki/Kanchipuram
@mvark
mvark / ai21-starter.py
Created August 9, 2024 15:57
AI21 API Starter Sample for Gen AI Beginners
"""
AI21 API Example: Get an answer to a question
"""
from ai21 import AI21Client
from ai21.models.chat import ChatMessage
import os
# Import necessary modules to work with the AI21 API
# AI21Client: Used to interact with the AI21 service
@mvark
mvark / TableColumnDeletion.js
Created July 7, 2024 06:29
JavaScript code to remove the last 2 columns of a 3-column table from the browser's developer console
// Select all table rows
const rows = document.querySelectorAll('table tr');
// Iterate through each row
rows.forEach(row => {
// Remove the last cell twice
row.removeChild(row.lastElementChild);
row.removeChild(row.lastElementChild);
});
@mvark
mvark / vitamins.csv
Last active May 24, 2024 18:48
Average values of micronutrients (vitamins) in various food groups (per 100g raw weight). Source: Indian Food Composition Tables 2017 & Nutritive Values of Indian Foods
Foods Vitamin B1 (Thiamine) (µg) Vitamin B2 (Riboflavin) (µg) Vitamin B3 (Niacin) (µg) Vitamin B6 (Pyridoxine) (µg) Vitamin B9, Total folates (µg) Vitamin C (mg) Vitamin A (Retinol) (µg) Vitamin D (D2) (µg)
Cereals 238.46 84.6 2138.5 162.31 15.86 0 2.01 6.88
Millets 355.56 155.6 2177.8 113.33 24.17 0 1.02 6.1
Pulses 400 158.8 2123.5 215.53 157.06 0 8.32 8.69
GLVS 60 127.7 624.6 97.49 31.6 45.6 397.9 3.4
Roots & tubers 31.58 10.5 405.3 97.47 21.48 12.1 39.85 0.55
Vegetables 41.3 43.5 365.2 97.48 28.53 23.6 18.4 2.38
Nuts 390 140 3210 311.4 47.58 0.4 1.26 9.06
Fruits 34.78 21.7 369.6 65.04 11.41 36.7 35.48 3.62
Meat & poultry 81.82 109.1 2772.7 220 5.59 0 1.93 0