Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / StringCompressor.cs
Created January 29, 2018 13:49
Compress String into MemoryStream
public class StringCompressor {
readonly string _value;
public void StringCompressor(string value)
{
_value = value;
}
public MemoryStream ToCompressedStream1(CompressionLevel level)
{
@rezanid
rezanid / RegisterAssembly.ps1
Last active January 15, 2018 10:33
Register an assembly in GAC using PowerShell
[Reflection.Assembly]::LoadWithPartialName("System.EnterpriseServices") | Out-Null
[System.EnterpriseServices.Internal.Publish] $publish = new-object System.EnterpriseServices.Internal.Publish
$publish.GacInstall(<<FullFilePathToTheDll>>)
@rezanid
rezanid / Invoke-WebRequestV2.ps1
Last active December 6, 2017 09:37
Send any kind of HTTP request or call SOAP / Web Services in PowerShell V2
function Invoke-WebRequestV2 {
param (
[Parameter(Mandatory=$true)]
[uri]
$Uri,
[Parameter(Mandatory=$false)]
[string]
$Method,
[Parameter(Mandatory=$false)]
[string]
@rezanid
rezanid / AspNetCaching.cs
Last active September 28, 2017 07:27
Caching data in ASP.NET using Lazy<T>
class CachedDataSource
{
protected T RetrieveCachedData<T>(
string cacheKey, Func<T> fallbackFunction, CacheItemPolicy cachePolicy) where T : class
{
var originalData = new CacheItem<Lazy<T>>(new Lazy<T>(fallbackFunction));
var cachedData = (CacheItem<Lazy<T>>)_cacheProvider.AddOrGetExisting(cacheKey, originalData, cachePolicy);
if (cachedData != null)
{
Logger.LogMessage(SeverityLevels.Verbose,
@rezanid
rezanid / QueryDraftPages.caml.xml
Created September 13, 2017 12:55
CAML query to retrieve draft pages from SharePoint
<View>
<Query>
<OrderBy>
<FieldRef Name="_UIVersionString"/>
<FieldRef Name="LinkFileName" />
</OrderBy>
<Where>
<Or>
<Eq>
<FieldRef Name="_ModerationStatus"/>