This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter | |
from pdfminer.converter import TextConverter | |
from pdfminer.layout import LAParams | |
from pdfminer.pdfpage import PDFPage | |
from io import StringIO | |
path = "pdf/*.pdf" | |
def convert_pdf_to_txt(path): | |
rsrcmgr = PDFResourceManager() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PyPDF2 | |
import textract | |
import nltk | |
import re | |
from tika import parser | |
import heapq | |
import glob | |
sys.stdout = codecs.getwriter("iso-8859-1")(sys.stdout, 'xmlcharrefreplace') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.preprocessing import MinMaxScaler | |
# Import models | |
from pyod.models.cblof import CBLOF | |
from pyod.models.feature_bagging import FeatureBagging | |
from pyod.models.hbos import HBOS | |
from pyod.models.iforest import IForest | |
from pyod.models.knn import KNN | |
from pyod.models.lof import LOF | |
import matplotlib | |
df['X1'] = df['X'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT OBJECT_SCHEMA_NAME(c.object_id) SchemaName | |
,o.Name AS Table_Name | |
,c.Name AS Field_Name | |
,t.Name AS Data_Type | |
,t.max_length AS Length_Size | |
,t.precision AS Precision | |
FROM sys.columns c | |
INNER JOIN sys.objects o ON o.object_id = c.object_id | |
LEFT JOIN sys.types t ON t.user_type_id = c.user_type_id | |
WHERE o.type = 'U' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT @@Servername AS ServerName , | |
DB_NAME() AS DB_Name , | |
o.Name AS TableName , | |
i.Name AS IndexName | |
FROM sys.objects o | |
INNER JOIN sys.indexes i ON o.object_id = i.object_id | |
WHERE o.Type = 'U' -- User table | |
AND LEFT(i.Name, 1) <> '_' | |
-- Remove hypothetical indexes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- How to find the hierarchical dependencies | |
-- Solve recursive queries using Common Table Expressions (CTE) | |
WITH | |
TableHierarchy ( ParentTable, DependentTable, Level ) | |
AS | |
( | |
-- Anchor member definition (First level group to start the process) | |
SELECT DISTINCT | |
CAST(NULL AS INT) AS ParentTable , |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Foreign Keys | |
SELECT @@Servername AS ServerName , | |
DB_NAME() AS DB_Name , | |
parent.name AS 'TableName' , | |
o.name AS 'ForeignKey' , | |
o.[Type] , | |
o.Create_date | |
FROM sys.objects o | |
INNER JOIN sys.objects parent ON o.parent_object_id = parent.object_id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Heap tables (Method 1) | |
SELECT @@Servername AS ServerName , | |
DB_NAME() AS DBName , | |
t.Name AS HeapTable , | |
t.Create_Date | |
FROM sys.tables t | |
INNER JOIN sys.indexes i ON t.object_id = i.object_id | |
AND i.type_desc = 'HEAP' | |
ORDER BY t.Name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This works for T-SQL | |
SELECT u.name + '.' + t.name AS [table], | |
td.value AS [table_desc], | |
c.name AS [column], | |
cd.value AS [column_desc] | |
FROM sysobjects t | |
INNER JOIN sysusers u | |
ON u.uid = t.uid | |
LEFT OUTER JOIN sys.extended_properties td | |
ON td.major_id = t.id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Similar information can be derived from sp_who | |
SELECT @@Servername AS Server , | |
DB_NAME(database_id) AS DatabaseName , | |
COUNT(database_id) AS Connections , | |
Login_name AS LoginName , | |
MIN(Login_Time) AS Login_Time , | |
MIN(COALESCE(last_request_end_time, last_request_start_time)) | |
AS Last_Batch | |
FROM sys.dm_exec_sessions | |
WHERE database_id > 0 |