“Hello world” using python in Red hat

Before installing python on the Linux platform, you may have to install zlib package,

$ yum install zlib-devel

if any permission issue, then 
$ sudo yum install zlib-devel
Download python releases from python.org, you can choose the release version according to your need

$ wget https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz
unzip the downloaded file using the following command
$ tar xf Python-3.8.6.tgz
Change the directory to python directory

 $ cd Python-3.*
run the ./configure tool to prepare the build
$ run the ./configure tool to prepare the build
now using make command , start to build python
$ make
finally you can install python using the below command,
$ make install

if you face any permission issue, then use sudo

$ sudo make install

If you need to run multiple python releases in your platform, you have to use the below command, so it will not overwrite the existing python release
$ make altinstall
$ vim helloworld.py
# helloworld program
print('Hello world')

press “esc” and type ūüė° (save and exit)

now execute the python code

$ python helloworld.py

Translate incoming emails [Microsoft power flow]

This tutorial will help you to create a Power flow app that automatically translates the email content to any preferred language.


Click on the Automated flow

There will be many flow triggers available for power flow. choose “When a new email arrives” depends on your email setup

It may redirect the user to authenticate to access mailbox.

By default the mailbox folder will point to “Inbox”, it is flexible enough to change the folders.

We have additional options to create filter/rule for mails, example:
– if the subject has certain keywords
– If the mail received only from xxxx@xx.com
– etc.,
feel free to configure based on the need.

Click on “New step” and search for “translate” and then choose Microsoft Translator from the list of operations

First time when Microsoft translator is chosen, it will ask the user to provide the connection name, you don’t have to provide the key, yet it will translate the text. But the no of requests per day will be limited.

Based on the requirement, you can purchase the key from Microsoft cognitive servers, for now we are not going to use the key.

Connection name: <any name>
Subscription key : blank

NExt step is to choose the actions from Microsoft translator, They have three different actions available
1. Detect language – If the requirement is to just detect what the language of any content, this option is ideal
2. Translate text – If the content has to be translated to a different language, this would be the ideal option, In our example, we are going to use this option

The next step is to choose the target language to translate the actual content. In this example, it would be the mail content.
Microsoft Translator supports around 80 languages,

In this case, English has been selected as a target language, choose “Body” parameter in “text” field

Add a new step and choose “Mail” from the operations list. Now we are going to send an email notification with translated text

select “Send an email notification” and provide
1. email address, 2. Subject
In body, select “Translated Text” (this value is the output from the previous step “Microsoft translator”)

In below step, actual email body is also attached, so the user can cross-check the translation vs the original email.

Thanks

Open url using Selenium Chromedriver c#

This is a simple example to show how to navigate to url using selenium chromedriver

Install selenium webdriver using Nuget Package

PM> Install-Package Selenium.WebDriver.ChromeDriver -Version 80.0.3987.10600

Below code performs a navigation to google.com

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
using System.Collections.ObjectModel;
using System.Threading;
using System.Configuration;


namespace OpenURL
{
    class Program
    {
        static void Main(string[] args)
        {
            IWebDriver driver = null;
            try
            {

                //driver = new ChromeDriver(@"c:\temp\");//load chromedriver from desired folder.
                driver = new ChromeDriver(AppDomain.CurrentDomain.BaseDirectory);//load chromedriver from bin folder as nuget package deploys chrome driver .exe and other dlls into bin
                driver.Url = "https://www.google.com";//Set the url you would like to navigate
                driver.Manage().Window.Maximize();
                driver.Navigate();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception" + e.ToString());
            }

            finally
            {
                Thread.Sleep(2000);
                driver.Quit();
                Console.ReadLine();
            }
        }
    }
}

Use bin or desired folder to load chrome driver

 driver = new ChromeDriver(AppDomain.CurrentDomain.BaseDirectory);
//this helps loading chromedriver from bin folder
driver = new ChromeDriver(@"c:\temp\");
//this helps to load chromdriver.exe from temp folder.

Calculation in SharePoint Designer – Workflow

There are two ways to perform a calculation.

  1. By creating a calculated column for the library and use excel formulas
  2. Using SharePoint designer workflow.

This will help you to perform any calculations using workflow.

Select “Do calculation” from “Action”

you can perform basic mathematical operations like addition, multiplication, division, etc., and store into workflow variable.

Then the workflow variable can be updated into a library column

Sort Array object python

This code will help to sort any custom list object in ascending or descending order

accuracy=[
        {
            "Alg": "DecisionTree",
            "val": 90
        },
        {
            "Alg": "GradientBoosting",
            "val": 60
        },
        {
            "Alg": "LinearRegression",
            "val": 95
        },
        {
            "Alg": "LogisticRegression",
            "val": 96
        }
    ]

ascending=sorted(accuracy, key = lambda i: float(i['val']))
print(ascending)
desc=sorted(accuracy, key = lambda i: float(i['val']),reverse=True)
print(desc)
Output

[{'Alg': 'GradientBoosting', 'val': 60}, {'Alg': 'DecisionTree', 'val': 90}, {'Alg': 'LinearRegression', 'val': 95}, {'Alg': 'LogisticRegression', 'val': 96}]
[{'Alg': 'LogisticRegression', 'val': 96}, {'Alg': 'LinearRegression', 'val': 95}, {'Alg': 'DecisionTree', 'val': 90}, {'Alg': 'GradientBoosting', 'val': 60}]

Create simple application using Microsoft LUIS (1/2)

This article will help developers to create a simple AI application using Microsot LUIS. In the below example, we will be able to create one simple conversation with Microsoft LUIS. (Ex: who are you? ) and LUIS will understand command provided.

People may use various way to find out about one. So we are going to put all those sentences as intents  (Ex: Who are you? , what are you? , who. etc.,) 


go to https://www.luis.ai/


Click on Create new app

For an example i have given as “hello world”.


Once the app has been created, we need to create intents. There are lot of prebuilt intents available from microsoft that can be used. (Example  Music related, Fitness related, places, travel, etc.,)

the intent name is “Who”


this is where we start populating intent sentences for “Who“, i have given four sentences just for an article purpose.


once intents are populated, it is important to click on “Train”. this will be automatically added to the training data. If the train button shows red, then some new intents are not yet added to the model ,¬†so it is important the “Train” button shows green

 


once the data has been trained, you can perform  a small testing by providing various commands and monitor the top scoring intent. it should match the intent you have created.

 


Once the testing is done, proceed to publish tab and push it to production. It generates an URL which contains the key and the subscription id for the app.
This url will be used in the application

o

Continue to the next article to see the implementation of LUIS in .net

Read Excel file using Python

This article shows how to import data from Excel using Python.

Step 1: install pandas

open Ananconda Command Prompt

Step 2: install pandas

\> pip install pandas

Read excel file

import pandas as pd
dataset1=pd.read_excel("C:/folderpath/filname.xlsx",sheet_name="sheetname")
dataset1.head()
print(dataset1.get("columnname"))

Read data from CSV File

import pandas as pd
dataset1=pd.read_csv("C:/foldername/filename.csv",encoding='ISO-8859-1')
dataset1.head()
print(dataset1.get("columnname"))

Access javascript variable from GeckoFx

This article helps developers to retrieve javascript variables from any webpage.
Two things are covered in the below code.

  • Injecting javascript into any webpage
  • Accessing javascript variable from the webpage.

Step 1: Navigating to the webpage (“https://gcatch.in/wp-content/uploads/2018/03/GecoFx.html”)


GeckoWebBrowser browser_gecko= new GeckoWebBrowser();
browser_gecko.Navigate("https://gcatch.in/wp-content/uploads/2018/03/GecoFx.html");
browser_gecko.DocumentCompleted += browser_DocumentCompleted_gecko;


private void browser_DocumentCompleted_gecko(object sender, GeckoDocumentCompletedEventArgs e)
{

            string jCode = " function variable() {return geckovariable;}"; // geckovariable is the variable name that exists in the webpage.
            GeckoElement script = browser_gecko.Document.CreateElement("script");
            script.TextContent = jCode;
            GeckoNode res = browser_gecko.Document.Head.AppendChild(script);

            string outString = "";
            AutoJSContext context = new AutoJSContext(browser_gecko.Window);
            JsVal result = context.EvaluateScript("variable()", browser_gecko.Window.DomWindow);
}

GeckoFx in WPF

Webbrowser component for WPF application. Default web browser component may have some limitation in terms of rendering webkits, html5.

GecoFx will help to render html5, etc.,
Below is a sample , how integrate GecoFx into your WPF Application

Install GecoFx from Nuget
PM> Install-Package GeckoFX -Version 1.0.5

Below are some of the functionalities frequency used with GeckoFx

  1. How to Invoke a script from GecoFx Control
    if user needs to execute a certain javascript function found in html page , you can use the below code to trigger the function.

    
    GeckoWebBrowser browser_gecko= new GeckoWebBrowser();
    browser_gecko.Navigate("https://gcatch.in/wp-content/uploads/2018/03/GecoFx.html");
    browser_gecko.DocumentCompleted += browser_DocumentCompleted_gecko;

     


    https://gcatch.in/wp-content/uploads/2018/03/GecoFx.html , you can check the page source and check javascript code for reference. below code will execute the function geckofunctioncheck

    
    private void browser_DocumentCompleted_gecko(object sender, GeckoDocumentCompletedEventArgs e)
    {
    AutoJSContext context = new AutoJSContext(browser_3w.Window); 
    context.EvaluateScript("geckofunctioncheck()"); 
    }
    


 
Namespaces



using Gecko;
using Gecko.Events;

Sharepoint Item level security – Workflow

Sharepoint has a feature to set item level security either manually or through workflow. In some case we might need to dynamic. (Ex: When we restrict people to view only their region data, we can either create different views per region or create a workflow to set the security level based on their region ) . But if its a sensitive data, creating a view doesnt make sense. Somehow we can pull up the data even by creating our own view). This article shows you how to set item level security using SharePoint workflow

1. Select impersonation step, it creates an unique step 

2. Now if you click on “Action”, you will notice some new list actions. Add list permission, Inherit list permission, …

with this actions, you can¬†modify current item’s permission or any other list’s item permission.