Skip to content

Instantly share code, notes, and snippets.

View AsishP's full-sized avatar

Asish Padhy AsishP

  • Sydney, Australia
View GitHub Profile
public string getTranslatedText(string text)
{
string host = "https://api.cognitive.microsofttranslator.com";
string route = "/translate?api-version=3.0&to=en";
string translatedText = "";
System.Object[] body = new System.Object[] { new { Text = text } };
var requestBody = JsonConvert.SerializeObject(body);
using (var client = new HttpClient())
public string DetectLanguageFromText(string text)
{
log.Info($"Got Text {text}");
string detectedLanguage = "";
var result = client.DetectLanguageAsync(new BatchInput(
new List<Input>()
{
new Input("1", text)
})).Result;
public TextAnalyticsProcessing(TraceWriter Log)
{
log = Log;
log.Info("Text Processing Section Called");
// Create a client.
client = new TextAnalyticsClient(new ApiKeyServiceClientCredentials())
{
Endpoint = "https://australiaeast.api.cognitive.microsoft.com"
}; //Replace 'australiaeast' with the correct region for your Text Analytics subscription
log.Info("Text Processing section initialized");
@AsishP
AsishP / AddUpdateSPHttpClient.ts
Last active May 6, 2019 22:25
Add/Update with SP Http Client
try
{
let addorUpdateObj : any = {
AuthorId : customObj.user.id,
__metadata : {
'type': `SP.Data.CustomListItem`
}
}
console.log(`Sending object ${addorUpdateObj}`);
@AsishP
AsishP / GetSPDataHttpClient.ts
Created May 6, 2019 21:26
Get operation using SP Http Client
try {
let spHttpClient : SPHttpClient = context.spHttpClient;
let url = `${context.pageContext.web.absoluteUrl}/_api/web/lists/GetByTitle('${listTitle}')/Items?$select=Author/EMail,*&$expand=Author&$filter=Author/EMail eq 'XYZ@xyz.com'`;
spHttpClient.get(url, SPHttpClient.configurations.v1).then((response : SPHttpClientResponse) => {
if(response.ok)
{
response.json().then((responseJson : any) => {
console.log(responseJson);
if (this.isValidObject(responseJson) && responseJson.value.length !== 0) {
resolve({
@AsishP
AsishP / SingleWebPartApp.ps1
Last active February 27, 2019 09:08
Add Single Web Part App Page
Connect-PnPOnline -Url "https://sharepoint.com"
## Add Page using PnP PowerShell
$page = Add-PnPClientSidePage -Name "TestAppPart.aspx" -LayoutType SingleWebPartAppPage
## Add a section the Page
Add-PnPClientSidePageSection -Page $page -SectionTemplate OneColumnFullWidth
## Add a Client Side Web Part
Add-PnPClientSideWebPart -Page $page -DefaultWebPartType SiteActivity -Section 0 -Column 0
export default class MasterComponent extends React.Component<MasterComponentProps, MasterComponentState> {
constructor()
{
super();
this._childSelect = this._childSelect.bind(this);
this.state= {
stateprop1 : null,
stateprop2 : true
}
import * as React from 'react';
import { ChildComponentState } from './ChildComponentState';
import { WebPartContext } from '@microsoft/sp-webpart-base';
export interface ChildComponentProps
{
context : WebPartContext;
childoutput?: (item: any) => void;
}
@AsishP
AsishP / Get data from Office 365 Azure Log
Last active July 17, 2019 04:57
Get data from Office 365 Azure Log
using System;
using System.Collections.Generic;
using System.Net.Http.Headers;
using System.Web;
using Newtonsoft.Json.Linq;
using System.Net.Http;
using Newtonsoft.Json;
using System.IO;
using Microsoft.Extensions.Logging;
using System.Linq;
@AsishP
AsishP / Connect to Azure AD in Azure Function
Last active June 13, 2019 09:29
Connect to Azure AD in Azure Function
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using System.Collections.Generic;
using Newtonsoft.Json;
using Microsoft.Azure.WebJobs.Extensions.Http;
using System.Threading.Tasks;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.Extensions.Logging;