Posts

PowerShell to find hyperlink text in word or pdf

In continuation to my previous article on PowerShell to find hyperlink texts in ppt , here I am going to show how to find hyperlinks in Word or PDF files. Sample code below, tweak it for your purpose and drop me a comment if you need help. $FilePath= "C:\Users\xxx\"  $OurDocuments = Get-ChildItem -Path "$FilePath" -Filter "*.pdf" -Recurse #change to .doc* for word $Word = New-Object -ComObject word.application $Word.Visible = $false $i = 0 $OurDocuments | ForEach-Object { try {     $Document = $Word.Documents.Open($_.FullName,$false,$true)      #"Processing file: {0}" -f $Document.FullName          try{     $Document.Hyperlinks | ForEach-Object {         if ($_.Address -like "https://domain.com*" -or $_.Text -like "https://domain.com*")          {                 "Found issues {0} `r`n" -f $Document.Fullname       ...

Installing MariaDB-Server on Ubuntu using sudo

This article demonstrate steps to install MariaDB/MySQL on Ubuntu using sudo. This is part of our getting started journey to learn MariaDB/MySQL. I will be covering PostgreSQL in another article. Before we get started, very first step would be to install MariaDB/MySQL Server and client. You can install any of these RDBMS on Windows but this blog will mostly be following Ubuntu OS. There are various tools to access MariaDB/MySQL Server, we are going to use mysqlclient and Heidisql. Lets get started with installation of MariaDB. Step 1: Open your Ubuntu terminal window or bash and run following cmd. This step is going to check if mariadb-server is already installed and is going to remove it. You can either continue using the current setup or go to next step to do a fresh installation sudo apt-get remove mariadb-server Step 2: run sudo apt-get install software-properties-common Step 3: Check for Ubuntu updates sudo apt-get updates Step 4: Install Ubuntu updates sudo ...

PostgreSQL PSQL Commands

To connect to postgresql using psql, update port, dbname, user and your_password in cmd below psql "host=localhost port=5432 dbname={your_database} user=user password={your_password} sslmode=require" To import data dump from .sql file using psql, use following cmd psql > \i 'path-to-dump.sql' Having single quote around the path is important else you may see C:: permission denied error. If using sudo  sudo -u postgres psql db_name < 'file_path' Create user  postgres=# create user user_name password 'password'; Create database  postgres=# create database mydb owner user_name ; Install PostgreSQL Client on Ubuntu bash:=# apt install postgresql-client- ; To Quit bash:=# \q ; Help bash:=# \h ; To describe attributes of a table. bash:=# \d tablename ; To get list of databases. bash:=# \l ; To connect to a database. bash:=# \c databasename ; To list all details of a database. bash:=# \z or select * from pg_tables where s...

Drop database in Oracle

Steps to drop a container database in oracle Step 1 : Connect to the database as sysdba bash#$ sqlplus / as sysdba Step 2 : Shutdown the database SQL> shutdown immediate; Step 3 : Start mount the database with exclusive restrict to avoid the database being opened SQL> startup mount exclusive restrict; Step 4 : Drop database SQL> drop database;

nth Highest Salary using window function in sql server

Image
A very common question which you will hear in interviews. How to find nth highest salary? Let's do it: The first step, create a table create table #Employee(id int, name varchar(15), salary int); Insert Dummy Data insert into #Employee(id,name,salary) values(1,'A',100) insert into #Employee(id,name,salary) values(2,'B',102) insert into #Employee(id,name,salary) values(3,'C',106) insert into #Employee(id,name,salary) values(4,'D',102) insert into #Employee(id,name,salary) values(5,'E',108) insert into #Employee(id,name,salary) values(6,'F',110) insert into #Employee(id,name,salary) values(7,'G',117) Let's see what we have in the table select * from #Employee; Query to find 3rd Highest Salary using row_number() select a.id,a.name,a.salary from ( select e.id,e.name,e.salary, row_number() over(order by salary) as rn  from #Employee e) as a where rn=3; output: 

Running Total In SQL Server

Running total refers to the sum of values in all cells of a column that precedes the next cell in that particular column. Using Window Function Assuming, the table has 2 columns, col1 is primary key with data type integer and col2 is integer data type values. To calculate running total on col2 write a query as select col1, col2,sum(col2) over(order by col1) as runnintotal from tablename using window function is more performance efficient.

Delegates in C#

Let's start with a very basic definition of Delegates in the real world. Delegates in the real world refer to transferring the work/tasks assigned to self to someone else. A team leader, supervisor, the manager can delegate work to his subordinate. A  delegate in C#  is similar to a function pointer in C or C++. Using a  delegate  allows the programmer to encapsulate a reference to a method inside a  delegate  object. The  delegate  object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked. When to use Delegate : Source: https://msdn.microsoft.com/en-us/library/ms173173.aspx Use a delegate in the following circumstances: An eventing design pattern is used. It is desirable to encapsulate a static method. The caller has no need to access other properties, methods, or interfaces on the object implementing the method. An easy composition is des...