Skip to content

Instantly share code, notes, and snippets.

View Nempickaxe's full-sized avatar
🤔
print('hi')

Nem_pickaxe Nempickaxe

🤔
print('hi')
View GitHub Profile
@Nempickaxe
Nempickaxe / index.html
Created January 15, 2024 14:27
basic HTML, CSS, JS example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Magical Recipes</title>
<style>
body {
background-color: #f5e3f8; /* Magical pastel purple */
font-family: 'Cursive Magic', fantasy;
@Nempickaxe
Nempickaxe / min_future_delta_date.py
Last active November 16, 2023 20:08
Create a new column with the minimum difference (in days) between today's date and future dates.
import pandas as pd
from datetime import datetime
def min_date_difference(df, date_columns):
"""
Create a new column with the minimum difference (in days) between today's date and future dates.
Parameters:
- df: pandas DataFrame
- date_columns: list of str, column names containing datetime values
def print_shri_shri(rows):
for i in range(rows):
for j in range(rows - i - 1):
print(" ", end=" ")
for j in range(i + 1):
print("श्री ", end="")
print()
@Nempickaxe
Nempickaxe / generate_upi_qr_code.py
Created May 5, 2023 09:49
Generate UPI code to receive payment at merchant's end
import qrcode
def generate_upi_qr_code(merchant_upi_id, merchant_name, payment_description, payment_amount):
# create the QR code string
qr_string = "upi://pay?pa={}&pn={}&tn={}&am={}".format(merchant_upi_id, merchant_name, payment_description, payment_amount)
# generate the QR code
qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4)
qr.add_data(qr_string)
qr.make(fit=True)
@Nempickaxe
Nempickaxe / download_google_fit_data.py
Created April 19, 2023 09:34
download google fit data through GCP project enabling fitness API
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from datetime import datetime, timedelta
import pandas as pd
from google_auth_oauthlib.flow import InstalledAppFlow
# Replace with the path to your credentials.json file
credentials_path = 'fitternew.json'
# Define the scopes that your app needs
@Nempickaxe
Nempickaxe / xml_parse.py
Last active April 19, 2023 07:06
xml to json conversion
import xmltodict
import json
# Specify the input and output file paths
input_file = 'input.xml'
output_file = 'output.jsonl'
# Open the input and output files
with open(input_file, 'r') as xml_file, open(output_file, 'w') as jsonl_file:
# Parse the XML file using xmltodict
@Nempickaxe
Nempickaxe / read_mongo.py
Created September 9, 2021 07:57
Read from Mongo
def read_mongo_collection(uri, pipeline=None, given_schema=None, spark=None):
"""
:param uri: uri for mongo connection
:param pipeline: pipeline option for pushing queries to mongo
:param given_schema: schema option, will read in mentioned schema
:return: dataframe after reading from mongo
"""
if pipeline:
if not given_schema:
return spark.read.format("com.mongodb.spark.sql.DefaultSource").option("pipeline", pipeline).option(
@Nempickaxe
Nempickaxe / get_size_variable.py
Created August 25, 2021 13:55
Get memory requirement for a variable
import sys
from types import ModuleType, FunctionType
from gc import get_referents
# Custom objects know their class.
# Function objects seem to know way too much, including modules.
# Exclude modules as well.
BLACKLIST = type, ModuleType, FunctionType
@Nempickaxe
Nempickaxe / split_text_max_width.py
Last active February 11, 2021 15:52
split a sentence based on maximum character width of sentences
def get_interval(space_list, width):
for i in range(len(space_list)-1):
if space_list[i+1]>width:
return space_list[i]
else:
continue
return space_list[-1]
def get_subtracted_list(space_list, width):
return list(map(lambda x: int(((x-width)+abs(x-width))/2), space_list))
import re
import yaml
def parse_config(vars_dict, path=None, data=None, tag='!ENV'):
"""
Load a yaml configuration file and resolve any environment variables
The environment variables must have !ENV before them and be in this format
to be parsed: $<VAR_NAME>.
E.g.:
database: