Skip to content

Instantly share code, notes, and snippets.

@bozhink
bozhink / XmlDocumentDeserializer.cs
Created October 24, 2016 09:57
Deserialize XmlDocument to object
/// <summary>
/// Deserializes XmlDocument object to Serializable object of type T.
/// </summary>
/// <typeparam name="T">Serializable object type as output type.</typeparam>
/// <param name="document">XmlDocument object to be deserialized.</param>
/// <returns>Deserialized serializable object of type T.</returns>
public static T Deserialize<T>(this XmlDocument document)
where T : class
{
XmlReader reader = new XmlNodeReader(document);
@bozhink
bozhink / XDocumentToXmlDocument.cs
Created October 24, 2016 09:40
Extension method to transform XDocument to XmlDocument
/// <summary>
/// Converts XDocument to XmlDocument.
/// Original source: <see cref="http://stackoverflow.com/questions/1508572/converting-xdocument-to-xmldocument-and-vice-versa"/>
/// </summary>
/// <param name="document">XDocument instance to be converted.</param>
/// <returns></returns>
public static XmlDocument XToXmlDocument(this XDocument document)
{
XmlDocument xmlDocument = new XmlDocument();
using (XmlReader xmlReader = document.CreateReader())
@bozhink
bozhink / XmlDocumentToXDocument.cs
Created October 24, 2016 09:38
Extension method to transform XmlDocument to XDocument
/// <summary>
/// Converts XmlDocument to XDocument.
/// Original source: <see cref="http://stackoverflow.com/questions/1508572/converting-xdocument-to-xmldocument-and-vice-versa"/>
/// </summary>
/// <param name="xmlDocument">XmlDocument instance to be converted.</param>
/// <returns></returns>
public static XDocument XmlToXDocument(this XmlDocument xmlDocument)
{
using (XmlNodeReader nodeReader = new XmlNodeReader(xmlDocument))
{
namespace ExpressionTest
{
using System;
using System.Linq.Expressions;
public static class Program
{
public static void Main(string[] args)
{
string str = "Test";
<input type="text" name="locations" list="places">
<datalist id="places">
<option>Amman, Jordan</option>
<option>New York, NY, USA</option>
<option>Paris, France</option>
<option>Vienna, Austria</option>
</datalist>
<!-- https://docs.webplatform.org/wiki/html/elements/datalist -->
distinct-values(//tp:treatment-sec/@sec-type/lower-case(.))
@echo off
color 0A
title Conditional Shutdown
:start
echo What would you like to do?
echo.
echo 1. Shutdown in specified time
echo 2. Shutdown now
echo 3. Restart now
@bozhink
bozhink / Scilab linear regression
Created March 15, 2014 11:48
Simple linear regression finction for Scilab
function [a,b]=linlsq(X,Y)
[n,m]=size(X);
n=n*m;
sumx = sum(X);
sumy = sum(Y);
sumxx = sum(X.*X);
sumxy = sum(X.*Y);
a=(sumx*sumy-n*sumxy)/(sumx*sumx-n*sumxx);
b=(sumy-a*sumx)/n;
endfunction
@bozhink
bozhink / PHP-cli XSLT
Created March 15, 2014 11:46
Command line XSL Transformation using PHP
#!/usr/bin/php
<?php
if (empty($argv[1]) || empty($argv[2])) { die ("Usage: $argv[0] <xml-file> <xsl-file>\n"); }
$xmlFile = $argv[1];
$xslFile = $argv[2];
$dom = new domDocument();
$dom->load($xslFile);
$proc = new xsltprocessor;