Skip to content

Instantly share code, notes, and snippets.

View j-thepac's full-sized avatar

Deepak j-thepac

View GitHub Profile
@j-thepac
j-thepac / readSynapseServerlessTableViews.py
Created July 2, 2024 12:52
Read Views / Tables in Azure Synapse using Notebooks
server_name = "jdbc:sqlserver://xxxx-dev-cca-weu-syn-01-ondemand.sql.azuresynapse.net"
database_name = "mydb"
url = server_name + ":1433;" + "databaseName=" + database_name + ";"
table_name = "T" #View / Table
accessToken = mssparkutils.credentials.getToken('DW')
df = (spark.read \
.format("com.microsoft.sqlserver.jdbc.spark") \
.option("url", url) \
.option("dbtable", table_name) \
@j-thepac
j-thepac / importantResources.md
Last active May 26, 2024 09:05
importantResources

Important Resources

Open Applications

  • OSX - open is a universal opener in OSX
  • Linux - has xdg-open (open bashrc > add "alias open = xdg-open" > save file >source ./bashrc)
  • Windows - use start

Online Virtual terminals

@j-thepac
j-thepac / drop_Table_SynapseNotebooks_Python.py
Created April 12, 2024 11:07
drop_Table_SynapseNotebooks_python
"""
db=DedicatedSQLAuth()
res=db.ddlStatements("drop table my_schema.A")
"""
class DedicatedSQLAuth():
def __init__(self):
self.dbName= "myDb"
self.serverName="myServer"
self.token= mssparkutils.credentials.getToken("DW")
@j-thepac
j-thepac / dropTableSynapseNotebook.scala
Last active April 11, 2024 11:47
drop Table using Synapse Notebook
/*.
supports to 4 parameter types: int, float, bool, string.
%run /<path>/Notebook1 { "parameterInt": 1, "parameterFloat": 2.5, "parameterBool": true, "parameterString": "abc" }.
*/
@j-thepac
j-thepac / deltaTest.py
Created March 9, 2024 07:35
TestDelta Logic
# %%
import os
# %%
os.system("pip3 install pyspark==3.3.2")
# %%
import findspark
findspark.init('/Users/deepakjayaprakash/Downloads/spark-3.3.2-bin-hadoop3/')
@j-thepac
j-thepac / Streaming_kafka_nse.py
Created January 7, 2024 08:58
Real Time Kafka Streaming NSE StockMarket Data
# %%
import httpx
# %%
url = "https://www.nseindia.com/api/marketStatus"
headers = {
"Accept": "*/*",
"Accept-Language": "en-US,en;q=0.9,hi;q=0.8",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
}
@j-thepac
j-thepac / error.py
Last active January 7, 2024 04:17
java.lang.NoSuchMethodError: org.apache.spark.sql.AnalysisException.<init>(Ljava/lang/String;Lscala/Option;Lscala/Option;Lscala/Option;Lscala/Option;
"""
PYSPARK
Py4JJavaError: An error occurred while calling o560.save.
: java.lang.NoSuchMethodError: org.apache.spark.sql.AnalysisException.<init>(Ljava/lang/String;Lscala/Option;Lscala/Option;Lscala/Option;Lscala/Option;)V
at org.apac
@j-thepac
j-thepac / India StockExchange Api.py
Last active November 4, 2024 19:05
Requests and Cookies with Example of NSE - Stock Exchange
# Session Management with API
import requests,httpx
def bse():
reqUrl = "https://api.bseindia.com/RealTimeBseIndiaAPI/api/GetSensexData/w"
headersList = {"Referer": "https://www.bseindia.com/" }
response = requests.GET(reqUrl, headers=headersList)
print(response.text)
@j-thepac
j-thepac / tenacity.py
Created December 19, 2023 10:23
Tenacity with Asyncio
from tenacity import (retry
,stop_after_attempt
,wait_fixed
,retry_if_exception_type
,stop_after_delay)
import httpx
import asyncio
import socket
@retry(stop=(stop_after_delay(3) | stop_after_attempt(5)),wait=wait_fixed(2),retry=retry_if_exception_type(Exception))
async def stop_after_7_attempts(): #stop_after_10s_or_5_retries
@j-thepac
j-thepac / Editor.md
Last active December 17, 2023 07:22
Editor Settings

DBeaver

Window > Preferences > Editors > Text Editors "Background Color"

VS Code

VS Code > Settings > Settings > run code

"workbench.colorCustomizations": { "editor.background": "#D5D8DC"