Skip to content

Instantly share code, notes, and snippets.

View angusdev's full-sized avatar

Angus angusdev

View GitHub Profile
@angusdev
angusdev / dash_chatbot.py
Last active April 3, 2025 21:30
Postgresql generate insert statement
import uuid
from abc import ABC, abstractmethod
from typing import Any, Optional
import dash
import flask
from dash import Input, Output, State, dcc, html
from dash.development.base_component import Component
@angusdev
angusdev / change_favicon_color.js
Last active October 18, 2024 19:48
genicon.js - Generate icon with text
change_favicon_color=(c)=>{u=window.top.document.querySelector('link[rel="icon"], link[rel="shortcut icon"]');if(u.href.startsWith('data:')){console.log('Favicon is already a data URL.');return;}fetch(u.href).then(r=>r.blob()).then(b=>{i=new Image();i.src=URL.createObjectURL(b);i.onload=()=>{a=document.createElement('canvas'),ctx=a.getContext('2d');a.width=i.width;a.height=i.height;ctx.drawImage(i,0,0);ctx.globalCompositeOperation='source-in';ctx.fillStyle=c;ctx.fillRect(0,0,a.width,a.height);u.href=a.toDataURL('image/x-icon');}})};
import re
from datetime import datetime
import pandas as pd
import argparse
def parse_log_files(file_names):
job_data = {}
job_pattern = re.compile(r'(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) (Thread-\d+) MYJOB (started|ended) (\d+) (.+)')
for file_name in file_names:
from pyspark.sql import SparkSession
from pyspark.sql import Row
# Initialize Spark Session
spark = SparkSession.builder.appName("Vertical Display").getOrCreate()
# Example DataFrame
data = [("Alice", 25), ("Bob", 30)]
columns = ["Name", "Age"]
from typing import List, Dict, Any, Tuple, Optional
from sqlalchemy import create_engine, text
from sqlalchemy.engine import Engine, ResultProxy
import pandas as pd
from pyspark.sql import SparkSession, DataFrame as SparkDataFrame
# Base class DataAccess using SQLAlchemy
class DataAccess:
def __init__(self, conn_str: str):
self.engine: Engine = create_engine(conn_str)
@angusdev
angusdev / apple_runner.py
Created August 17, 2024 10:08
Python Dynamic Import Module
# apple_runner.py
class AppleRunner:
def run(self):
print("Apple")
@angusdev
angusdev / SqlWarehouseDataSource.py
Created August 8, 2024 21:19
SQL Warehouse Data Source
import pandas as pd
import requests
from datetime import datetime, timedelta
from databricks import sql
class SqlWarehouseDataSource:
def __init__(self, host: str, http_path: str, client_id: str, client_secret: str, tenant_id: str, token_expiry_threshold: int = 300):
"""
Initialize the SqlWarehouseDataSource class with Databricks SQL connection details.
@angusdev
angusdev / wiki-tennis-aus-2025.js
Last active January 10, 2025 22:38
Make a printable version of tennis draw in Wiki
e=document.querySelector('#Top_half').parentNode.nextSibling;while(e.previousSibling)e.parentNode.removeChild(e.previousSibling);
e=document.querySelector('#bodyContent');while(e.previousSibling)e.parentNode.removeChild(e.previousSibling);
e=document.querySelector('.mw-page-container');while(e.previousSibling)e.parentNode.removeChild(e.previousSibling);
e=document.querySelector('#mw-content-text');while(e.previousSibling)e.parentNode.removeChild(e.previousSibling);
e=document.querySelector('.mw-content-container');while(e.previousSibling)e.parentNode.removeChild(e.previousSibling);
e=document.querySelectorAll('#Seeds,#Seeded_players').forEach(e=>{e=e.parentNode.previousSibling;while(e.nextSibling && (!e.nextSibling.querySelector||!e.nextSibling.querySelector('#Top_half')))e.parentNode.removeChild(e.nextSibling)});
document.querySelectorAll('.mw-editsection,#catlinks,.mw-footer-container,.vector-settings').forEach(e=>e.parentNode.removeChild(e));
document.querySelectorAll('#Section_3,#Bottom_half,#Section_7').
@angusdev
angusdev / tabcount.sql
Last active May 16, 2024 14:23
Select count of all tables
#!/bin/bash
# Check if directory path is provided as an argument
if [ $# -ne 1 ]; then
echo "Usage: $0 <directory_path>"
exit 1
fi
directory="$1"