Skip to content

Instantly share code, notes, and snippets.

@rezanid
rezanid / Text.cs
Created January 31, 2018 06:55
String operations Faster than out-of-the-box .NET
public class Text
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsWhiteSpace(char ch)
{
// this is surprisingly faster than the equivalent if statement
switch (ch)
{
case '\u0009':
case '\u000A':
@rezanid
rezanid / SharePoint-CSOM-CheckCertificate.cs
Created June 25, 2018 06:16
SharePoint CSOM - Custom server certificate (HTTPS) validation at client side.
void ValidateSharePointCertificate()
{
ClientContext context = new ClientContext("https://[sharepointserver]");
ServicePointManager.ServerCertificateValidationCallback = delegate(object sender1, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
bool validationResult = true;
return validationResult;
};
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(customXertificateValidation);
context.ExecutingWebRequest +=new EventHandler<WebRequestEventArgs>(context_ExecutingWebRequest);
@rezanid
rezanid / azureMonitor-query-highCpuProcess.txt
Created October 12, 2018 19:24
Azure Monitor Query - which processes taking more resources
#Which process was taking up a lot of processing resource over the last two hours in a specific machine?
#(don't be surprised if it is more that 100% because it can be a multi-core machine)
let startTime=ago(2hour)
let ednTime=now()
Perf
| where TimeGenerated between (startTime..endTime) and Computer == "(Contoso.Retail.com)" and ObjectName == "Process" and InstanceName !in ("_Total", "idle")
| make-series avg(CounterValue) default=0 on TimeGenerated in range(startTime, endTime, 10m) by InstanceName
| mvexpand TimeGenerated to typeof(datetime), avg_CounterValue to typeof(double) limit 100000
| render timechart
@rezanid
rezanid / AzureFunction-ZipDeploy.ps1
Created April 1, 2019 11:45
Deploy Azure Functions using REST API (ZipDeploy)
Function Deploy-AzureFunction(
[Parameter(Mandatory = $true)]
[String]$username,
[Parameter(Mandatory = $true)]
[String]$password,
[Parameter(Mandatory = $true)]
[String]$functionAppName,
[Parameter(Mandatory = $true)]
[String]$zipFilePath
)
@rezanid
rezanid / SharePoint-FindContentType.sql
Created January 14, 2020 13:52
Find a ContentType in SharePoint DB
SELECT [SiteId]
,[Class]
,[Scope]
,sys.fn_varbintohexstr([ContentTypeId]) as CT
,[Version]
,[NextChildByte]
,[Size]
,[Definition]
,[ResourceDir]
,[IsFromFeature]
@rezanid
rezanid / Git-Cheatsheet.md
Last active November 18, 2020 12:36
Git Cheat Sheet

When you have one remote

Commands can be shorter when you have only one remote Git server.

Fetch

git fetch

Checkout

git checkout name-of-the-remote-branch

Example output:

@rezanid
rezanid / KnockoutJS-ComputedField.ts
Created November 26, 2020 12:01
How to define a computed property in ViewModel, KnockoutJS, TypeScript
module SampleModule {
export class SampleComponent {
isValid: KnockoutComputed<boolean>;
//...
constructor(public element) {
//...
this.isValidConnectAs = ko.computed<boolean>({
owner: this,
read: () => {
@rezanid
rezanid / powerplatform-dialogs.js
Created December 28, 2021 13:55
Display model-driven custom page as dialogs in Power Platform
/* This function uses Navigation API to display a centered dialog. */
/* Simple parameters are used instead of object to make the function compatible with command bar parameters. */
function displayDialog(rowId, tableName, pageName, title, contentWidth, contentHeight, primaryControl) {
const parseSize = (str, defaultStr) => (str || defaultStr || "500px").match(/([\d\.]*)(.*)/).splice(1,2);
let [w, wUnit] = parseSize(contentWidth);
let [h, hUnit] = parseSize(contentHeight);
var pageInput = {
pageType: "custom",
name: pageName,
entityName: tableName,
@rezanid
rezanid / FetchUtil.cs
Created February 22, 2022 15:33
Power Platform (Dynamics) FetchXml serializer
using System.Xml.Linq;
namespace Playground
{
public class FetchUtil
{
private static readonly Type[] SimpleTypes = new Type[] { typeof(string), typeof(DateTime), typeof(Enum), typeof(decimal), typeof(Guid) };
public static XElement ToXml(string rootName, object? x, XElement? root = null)
{
if (x == null) { return new XElement(rootName); }
@rezanid
rezanid / JsonConverters.cs
Created May 7, 2023 19:05
Json Converters to facilitate unit testing for Power Platform's Custom APIs
using Microsoft.Xrm.Sdk;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
namespace MyFancyPlugins.Tests.JsonConverters;
/// <summary>
/// Allows serialization / deserialization of <see cref="Microsoft.Xrm.Sdk.EntityCollection". This type is
/// intended for unit-testing only./>