Sunday, 7 April 2019

Quick & dirty php serilaization

 class MYENC {
  private $STRESC = [ '"' => """, "'" => "'", '&' => "&", '>' => ">", '<' => "<", ];
  function STRENC($s) { 
   if (is_null($s)) return "N";
   $opc = 'P'; $rv = [];
   foreach (str_split($s) as $c) {
    $n = ord($c);
    if ($n <= 0x20 || $n > 126 || $n == ord('\\')) array_push($rv, sprintf(strtoupper("&#%x;"), $n));
    elseif (array_key_exists($c, $this->STRESC))  array_push($rv, $this->STRESC[$c]); 
    else array_push($rv, $c);
   }
   return join('',$rv);
  }
  function STRDEC($s) {
   if (is_null($s)) return $s;
   preg_match_all("/[&][^;]*;/", $s, $m, PREG_OFFSET_CAPTURE); 
   if (count($m) <= 0) return $s;
   $p = $m[0];
   if (count($p) <= 0) return $s;
   $ESC = array_flip($this->STRESC);
   for ($i = count($p)-1; $i >= 0; $i--) {
    $rep = ''; $x = $p[$i];
    if (array_key_exists($x[0], $ESC)) $rep = $ESC[$x[0]];
    else if (preg_match("/^[&][#]([0-9A-F]+);/i", $x[0], $h) > 0) $rep = chr(hexdec($h[1]));
    $s = substr_replace($s, $rep, $x[1], strlen($x[0]));
   }
   return $s;
  }
  private $CONTROL = [ "N" => [ 'arg' => 0, 'func' => '_N'],
              "A" => [ 'opc' => 'A', 'arg' => 0, 'func' => '_A'],
              "C" => [ 'opc' => 'C', 'arg' => 0, 'func' => '_C'],
              "P" => [ 'opc' => 'P', 'arg' => 1, 'func' => '_P'],
              "=" => [ 'opc' => '=', 'arg' => 0, 'func' => '_EQ'],
              "#" => [ 'opc' => '#', 'arg' => 0, 'func' => '_HASH'],
              "i" => [ 'opc' => 'i', 'arg' => 0, 'func' => '_INT'],
              "b" => [ 'opc' => 'b', 'arg' => 0, 'func' => '_BOOL'],
              "f" => [ 'opc' => 'f', 'arg' => 0, 'func' => '_FLOAT'],
  ];
  function __construct() { }
  private function    _N(&$S,$v) { array_push($S, NULL); }
  private function    _A(&$S,$v) { array_push($S, []); }
  private function    _C(&$S,$v) { array_push($S, new stdClass); }
  private function    _P(&$S,$v) { array_push($S, $v); }
  private function   _EQ(&$S,$v) { $v = array_pop($S); $f = array_pop($S); $C = array_pop($S); $C->$f = $v; array_push($S, $C); }
  private function _HASH(&$S,$v) { $v = array_pop($S); $f = array_pop($S); $A = array_pop($S); $A[$f] = $v; array_push($S, $A); }
  private function  _INT(&$S,$v) { $v = array_pop($S); array_push($S, intVal($v)); }
  private function _BOOL(&$S,$v) { $v = array_pop($S); array_push($S, !!intVal($v)); }
  private function _FLOAT(&$S,$v) { $v = array_pop($S); if ($v == 'NAN') $v = NAN; elseif ($v == 'INF') $v = INF; else $v = floatVal($v); array_push($S, $v); }
  private function NEXTOPC($P, $_off, &$opr, &$v) {
   $opr = NULL; $v = NULL;
   $idx = $_off;
   $CTL = $this->CONTROL;
   if ($idx < 0 || $idx >= strlen($P)) return 0;
   $op = $P[$idx];
   $idx++;
   if (!array_key_exists($op, $CTL)) return 0;
   $opr = $CTL[$op];
   if ($opr['arg'] == 0) return $idx - $_off;
   if (preg_match("/([0-9]+)[.]/", $P, $m, PREG_OFFSET_CAPTURE, $idx) <= 0) return 0;
   $k = $m[1];
   $idx += strlen($k[0]) + 1;
   $len = intVal($k[0]);
   if ($idx+$len > strlen($P)) return 0;
   $v = substr($P, $idx, $len);
   $idx += $len;
   return $idx - $_off;
  }
  function DECODE($P) {
   $STACK = []; $off = 0;
   for (;;) {
    $i = $this->NEXTOPC($P, $off, $opr, $v);
    if ($i <= 0) break;
    $off += $i;
    $func = $opr['func'];
    $this->$func($STACK, $v);
    #print "OPC " . $opr['opc'] . "\$i=${i} \$off=${off}\n";
   }
   return array_pop($STACK);
  }
  private function EMIT(&$K, ... $s) { $K .= join('', $s); }
  private function EMITS(&$K, ... $params) {
   foreach ($params as $s) {
    if (is_null($s)) { $this->EMIT($K, "N"); return; }
    $post = '';
    if (is_float($s)) {
     $post = 'f';
     if (is_nan($s)) $s = 'NAN'; elseif (is_infinite($s)) $s = 'INF'; else $s = sprintf("%.17e", $s);
    }
    elseif (is_int($s)) $post = 'i';
    elseif (is_bool($s)) $post = 'b';

    $this->EMIT($K, "P", strlen($s), ".", $s, $post);
   }
  }
  private function ENC(&$K, $X) {
   if (is_array($X)) {
    $this->EMIT($K, "A");
    foreach ($X as $k => $v) {
     if (is_array($v)) { $this->EMITS($K, $k); $this->ENC($K, $v); continue; }
     if (is_object($v)) { $this->EMITS($K, $k); $this->ENC($K, $v); continue; }
     $this->EMITS($K, $k, $v);
     $this->EMIT($K, "#");
    }
    return;
   }
   if (is_object($X)) {
    $this->EMIT($K, "C");
    foreach (get_object_vars ($X) as $k => $v) {
     if (is_array($v)) { $this->EMITS($K, $k); $this->ENC($K, $v); continue; }
     if (is_object($v)) { $this->EMITS($K, $k); $this->ENC($K, $v); continue; }
     $this->EMITS($K, $k, $v);
     $this->EMIT($K, "=");
    }
    return;
   }
   $this->EMITS($K,$X);
  }
  function ENCODE($X) { $K = ''; $this->ENC($K, $X); return $K; }
 }

http://onlinephpfunctions.com/

http://onlinephpfunctions.com/

Monday, 5 February 2018

Download tools from NuGet

12/06/2017

Applies to Dynamics 365 (online), version 9.x
You can download tools used in development from NuGet using the powershell script found below. These tools include:
ToolNuGet Package
Code generation tool CrmSvcUtil.exeMicrosoft.CrmSdk.CoreTools
Configuration Migration tool DataMigrationUtility.exeMicrosoft.CrmSdk.XrmTooling.ConfigurationMigration.Wpf
Package Deployer PackageDeployer.exeMicrosoft.CrmSdk.XrmTooling.PackageDeployment.WPF
Plug-in Registration Tool PluginRegistration.exeMicrosoft.CrmSdk.XrmTooling.PluginRegistrationTool
SolutionPackager tool SolutionPackager.exeMicrosoft.CrmSdk.CoreTools

Download tools using PowerShell

  1. In your Windows Start menu, type Windows Powershell and open it.
  2. Navigate to the folder you want to install the tools to. For example if you want to install them in a devtools folder on your D drive, type cd D:\devtools.
  3. Copy and paste the following PowerShell script into the PowerShell window and press Enter.
    PowerShell
    $sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
    $targetNugetExe = ".\nuget.exe"
    Remove-Item .\Tools -Force -Recurse -ErrorAction Ignore
    Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
    Set-Alias nuget $targetNugetExe -Scope Global -Verbose
    
    ##
    ##Download Plugin Registration Tool
    ##
    ./nuget install Microsoft.CrmSdk.XrmTooling.PluginRegistrationTool -O .\Tools
    md .\Tools\PluginRegistration
    $prtFolder = Get-ChildItem ./Tools | Where-Object {$_.Name -match 'Microsoft.CrmSdk.XrmTooling.PluginRegistrationTool.'}
    move .\Tools\$prtFolder\tools\*.* .\Tools\PluginRegistration
    Remove-Item .\Tools\$prtFolder -Force -Recurse
    
    ##
    ##Download CoreTools
    ##
    ./nuget install  Microsoft.CrmSdk.CoreTools -O .\Tools
    md .\Tools\CoreTools
    $coreToolsFolder = Get-ChildItem ./Tools | Where-Object {$_.Name -match 'Microsoft.CrmSdk.CoreTools.'}
    move .\Tools\$coreToolsFolder\content\bin\coretools\*.* .\Tools\CoreTools
    Remove-Item .\Tools\$coreToolsFolder -Force -Recurse
    
    ##
    ##Download Configuration Migration
    ##
    ./nuget install  Microsoft.CrmSdk.XrmTooling.ConfigurationMigration.Wpf -O .\Tools
    md .\Tools\ConfigurationMigration
    $configMigFolder = Get-ChildItem ./Tools | Where-Object {$_.Name -match 'Microsoft.CrmSdk.XrmTooling.ConfigurationMigration.Wpf.'}
    move .\Tools\$configMigFolder\tools\*.* .\Tools\ConfigurationMigration
    Remove-Item .\Tools\$configMigFolder -Force -Recurse
    
    ##
    ##Download Package Deployer 
    ##
    ./nuget install  Microsoft.CrmSdk.XrmTooling.PackageDeployment.WPF -O .\Tools
    md .\Tools\PackageDeployment
    $pdFolder = Get-ChildItem ./Tools | Where-Object {$_.Name -match 'Microsoft.CrmSdk.XrmTooling.PackageDeployment.Wpf.'}
    move .\Tools\$pdFolder\tools\*.* .\Tools\PackageDeployment
    Remove-Item .\Tools\$pdFolder -Force -Recurse
    
    ##
    ##Remove NuGet.exe
    ##
    Remove-Item nuget.exe    
    
  4. You will find the tools in the following folders:
  • [Your folder]\Tools\ConfigurationMigration
  • [Your folder]\Tools\CoreTools
  • [Your folder]\Tools\PackageDeployment
  • [Your folder]\Tools\PluginRegistration
To get the latest version of these tools, repeat these steps.

Sunday, 29 October 2017

Wednesday, 1 March 2017










real example of HTML Diamond code



Accounts
Customers


Html Diamond - HTML code

<!DOCTYPE html>
<!-- https://www.sitepoint.com/community/t/diamond-with-text-centered/35376/3 -->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="robots" content="">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />


<!--css-->
<link rel="stylesheet" href="css/master.css" />
<style type="text/css">
    * {
        padding: 0;
        font: 16px Helvetica, sans-serif;
    }

    .diamond {
        margin: 50px;
        width: 100px;
        height: 100px;
        background: red;
        transform: rotate(45deg);
        -ms-transform: rotate(45deg);
        -webkit-transform: rotate(45deg);
        border-radius:15px;
    }

    .diamond-inner {
        margin: 50px;
        color: #fff;
        font-weight: bold;
        font-size: 1.2em;
        line-height: 1.4em;
        text-align: center;
        transform: rotate(-45deg);
        -ms-transform: rotate(-45deg);
        -webkit-transform: rotate(-45deg);
        width:100px;
        height: 100px;
        display: table-cell;
        vertical-align: middle;
        text-align: center;
        border-radius:15px;
    }

</style>

<!--[if lt IE 9]>
         <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

<title>Title of the document</title>
</head>
<body>
    <div class="diamond">
        <div class="diamond-inner"> Business Starter </div>
    </div>
</body>
</html>

Saturday, 28 January 2017

Connect to SQL Server with Windows Authentication in a different domain - Database Administrators Stack Exchange

Connect to SQL Server with Windows Authentication in a different domain - Database Administrators Stack Exchange:

runas /netonly /user:domain\username "C:\path_to\ssms.exe""

Friday, 26 August 2016

Enable/Disable Network interface via command line - Microsoft Community

Enable/Disable Network interface via command line - Microsoft Community:
"netsh interface set interface name="Local Area Connection" admin=disabled"

'via Blog this'
Get NIC list and index number:
wmic nic get name, index

Enable NIC with index number: (eg: 7)
wmic path win32_networkadapter where index=7 call enable

Disable NIC with index number: (eg: 7)
wmic path win32_networkadapter where index=7 call disable

Thursday, 2 June 2016

Yacc/Lex Tools v0.2

http://ecianciotta-en.abriom.com/2013/08/yacclex-tools-v02.html

Tuesday, 12 April 2016

Generate Bitmap containing Centered Text

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication14
{
    class Program
    {
        static void Main(string[] args)
        {
            string txt = "HELLO";
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(131, 50);
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
            g.Clear(System.Drawing.Color.DarkGreen);
            System.Drawing.Font f = new System.Drawing.Font("Courier", 25, System.Drawing.FontStyle.Bold);
            System.Drawing.SizeF szf = new System.Drawing.SizeF();
            szf = g.MeasureString(txt, f);
            int xoff = (int)((bmp.Width - szf.Width) / 2);
            g.DrawString(txt, f, System.Drawing.Brushes.Red, new System.Drawing.Rectangle(/*x*/xoff, /*y*/0, bmp.Width, bmp.Height));
            bmp.Save("c:/temp/xxx.bmp");
        }
    }

}

C# Formax XML

     // Load the XmlDocument with the XML.
     document.LoadXml(fp.FetchXml);

     writer.Formatting = System.Xml.Formatting.Indented;

     // Write the XML into a formatting XmlTextWriter
     document.WriteContentTo(writer);
     writer.Flush();
     mStream.Flush();

     // Have to rewind the MemoryStream in order to read
     // its contents.
     mStream.Position = 0;

     // Read MemoryStream contents into a StreamReader.
     System.IO.StreamReader sReader = new System.IO.StreamReader(mStream);

     // Extract the text from the StreamReader.
     String FormattedXML = sReader.ReadToEnd();

     string[] Result = FormattedXML.Replace("\r", "").Split(new char[] { '\n'});
     foreach (string s in Result)
        Consolw.WriteLine("{0}", s);

Serialize CRM Object

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            Microsoft.Xrm.Sdk.Entity E = new Microsoft.Xrm.Sdk.Entity("entity");
            System.Runtime.Serialization.DataContractSerializer Sz =
                new System.Runtime.Serialization.DataContractSerializer(typeof(Microsoft.Xrm.Sdk.Entity));
            StringBuilder sb = new StringBuilder();
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            Sz.WriteObject(ms, E);
            string str = Encoding.ASCII.GetString(ms.ToArray());
        }
    }
}

Wednesday, 11 November 2015

JavaScript - Change URI port

var foo = document.createElement("a");
//foo.href = "http://www.example.com:8080/demo/";
foo.href = document.location.href;
foo.port = 8000;
document.location.href = foo.location.href ;

//var newURL = foo.href;
//console.log(newURL); // output: http://www.example.com:8000/demo/

Monday, 31 August 2015

JavaScript - CRM format

function pad(num, size) {
    var s = num + "";
    while (s.length < size) s = "0" + s;
    return s;
}
function formatDateForCRM(date) {
 var delta = (date.getHours() * 60 + date.getMinutes()) - (date.getUTCHours() * 60 + date.getUTCMinutes());
 var deltaS = "+";
 if (delta < 0) { deltaS = "-"; delta = 0 - delta; }
 var deltaM = (delta % 60);
 var deltaH = (delta - deltaM) / 60;
 var DateFilter = "datetime\'";
 DateFilter += pad(date.getUTCFullYear(), 4) + "-";
 DateFilter += pad(date.getUTCMonth() + 1, 2) + "-";
 DateFilter += pad(date.getUTCDate(), 2);
 DateFilter += "T";
 DateFilter += pad(date.getUTCHours(), 2) + ":";
 DateFilter += pad(date.getUTCMinutes(), 2) + ":";
 DateFilter += pad(date.getUTCSeconds(), 2);
 DateFilter += deltaS + pad(deltaH, 2) + ":" + pad(deltaM, 2);
 return DateFilter;
}

var X = new Date();
var S = formatDateForCRM(X);
print(S);

Friday, 24 April 2015

Microsoft Support Lifecycle

https://support.microsoft.com/en-us/lifecycle/search/default.aspx?sort=PN&alpha=sql%20server&Filter=FilterNO