2017-05-13

Deal with Annoying Popup New Tabs in Selenium

When I was trying to scraping a website using selenium webdriver, everytime I navigate to new url, a third party annoying advertisement page opened which I cannot block it out.

So I found out WindowHandler if Selenium which quite userful.

Simpley here is how I make it.


C#
public static void RemoveAdd()
{

    if (driver.WindowHandles.Count() > 1)
    {
        do
        {
         driver.SwitchTo().Window(driver.WindowHandles.Last());   
         driver.Close();   
         driver.SwitchTo().Window(driver.WindowHandles.Last());         
         } while (driver.WindowHandles.Count() > 1)         
     }

}





2017-05-11

Extract Video Frame Using FFmepg with C#

I have so many videos in harddrive need to indexed it and get it sorted. And last month I got the ideal uploading video images to Google Photo.

So I want to extract every frame of video every half minute. Here is how I do with C#.


Define function to call FFmepg

public static void Ffmpeg(string fileName)
    {

        string outFile = fileName.Substring(0, fileName.Length - 5);
        string cmdParams = String.Format("-hide_banner -i {0} -vf fps=1/30 {1}%03d.jpg", 
            fileName, outFile);  //fps=1/30 means every 30 seconds extract a frame

        string exePath = @"C:\Users\rockymay\OneDrive\RipAlbumUrl\ffmpeg.exe";
        
        using (Process p = new Process())
        {
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.FileName = exePath;
            p.StartInfo.Arguments = cmdParams;
            p.Start();
            p.WaitForExit();

            
        }
}



Then call out function in Main


class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(DateTime.Now);//Now time

            Console.WriteLine("Select your video file full path");
            string path = Console.ReadLine();
            Ffmpeg(path);
        }
    }


Thanks to :
https://www.codeproject.com/Articles/774093/Another-FFmpeg-exe-Csharp-Wrapper

Enforce DataField in ASP.Net WebForms

Place cssClass at



Revise asp.Boundfield as following:


Selenium Do not Load Picture


Add following Code to your automation so that ChromeDriver does not load picture while auto-testing
IWebDriver driver;
ChromeOptions options = new ChromeOptions();
options.AddUserProfilePreference("profile.default_content_setting_values.images", 2);
driver = new ChromeDriver(options);

2017-05-09

Progress Bar in Console


There is a working spinner example posted in stackoverflow as:
 public class ConsoleSpiner
    {
        int counter;
        public ConsoleSpiner()
        {
            counter = 0;
        }
        public void Turn()
        {
            counter++;
            switch (counter % 4)
            {
                case 0: Console.Write("/"); break;
                case 1: Console.Write("-"); break;
                case 2: Console.Write("\\"); break;
                case 3: Console.Write("-"); break;
            }
            Console.SetCursorPosition((Console.CursorLeft - 1), Console.CursorTop);
        }
    }


#####
ConsoleSpiner spin = new ConsoleSpiner();
 Console.Write("Working….");
while (true)
      {
         spin.Turn();
     }


##########
What I really looking for is the progress bar showing percentage.


Wait for it......

Bulk Rename Utility Download

The best batch rename program I ever encounter with.

Some times I would program myself using C#(Git) to movie files out in certain way that Bulk Rename cannot do.


Here is the download link for it.



//imge

2017-05-06

Find and Delete Duplicate Record in SQL

--Retrieve duplicate record
SELECT * FROM MovieDB
    WHERE Title in (SELECT Title FROM MovieDB GROUP BY Title HAVING COUNT(Title) > 1)


--Delete duplicate record,keep record with low Id value

DELETE FROM MovieDB
    WHERE Title IN (SELECT Title FROM MovieDB GROUP BY Title HAVING COUNT(Title) > 1) AND
    Id NOT IN (SELECT min(Id) FROM MovieDB GROUP BY Title HAVING COUNT(Title)>1)


--Replace value

UPDATE TableName SET columnName = REPLACE(columnName, 'previous value', 'new value')

--Updating value based on other table

UPDATE TableOne
SET Date1 = TableTwo.Date2
FROM TableOneTableTwo
WHERE
   TableOne.Title = TableOne.Title AND Date1 IS NULL


--Insert file value to table

BULK INSERT URLDate
FROM 'C:\Users\Admin\Desktop\sourceData.txt'
WITH    (
FIRSTROW = 1,   --data begin
FIELDTERMINATOR = '###',  --field delimiter
ROWTERMINATOR = '\n',   --Use to shift the control to next row
TABLOCK)


2017-05-05

Asp.net Add Indexing & Set HyperLink


##Insert Indexing for grid and Datadetail

<asp:TemplateField HeaderText="|  #  |">
                    <ItemTemplate>
                        <%# Container.DataItemIndex + 1 %>
                    </ItemTemplate>
                </asp:TemplateField>

##Set as URL Hyperlink
<asp:HyperLinkField DataNavigateUrlFields="url" HeaderText="URL" Text="LINK" />


<asp:HyperLinkField DataNavigateUrlFields="url" HeaderText="URL" Text="LINK" />


Setup VNC on Ubuntu 20.04

  sudo apt update sudo apt install xfce4 xfce4-goodies sudo apt install tigervnc-standalone-server sudo apt install tightvncserver vncserver...