Skip to content

Instantly share code, notes, and snippets.

@bozhink
bozhink / ExecuteProcess.cs
Last active February 24, 2023 04:30
Execute process in C# without console
using System;
using System.Diagnostics;
using System.Text;
public class Program
{
public static void Main(string[] args)
{
if (args.Length < 1)
{
@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 / install-dotnet-web-application-linux.md
Last active September 13, 2020 10:30
Install dotnet web application on Debian/Ubuntu-like Linux distribution

Install dotnet web application on Debian/Ubuntu-like Linux distribution

Fresh install of the OS

  1. Update the index of packages
$ sudo apt update
  1. Update (upgrade) installed packages
$ sudo apt upgrade
# See https://stackoverflow.com/questions/48341920/git-branch-command-behaves-like-less
git config --global pager.branch false
@bozhink
bozhink / disable-back.js
Created May 14, 2018 05:57
Disable back button with JavaScript
// See https://codepen.io/dhavalt10/pen/rGLBzB
history.pushState(null, null, location.href);
window.onpopstate = function () {
history.go(1);
};
@bozhink
bozhink / serialize-object.js
Created December 20, 2017 09:42
jQuery: serialize form to object
$.fn.serializeObject = function () {
var i, len, item, object = {}, array = $(this).serializeArray() || [];
len = array.length;
for (i = 0; i < len; i += 1) {
item = array[i];
object[item.name] = item.value;
}
return object;
}
@bozhink
bozhink / ReportPrinter.cs
Created November 7, 2017 10:59
C# WinForms Report Printer
public class ReportPrinter : IDisposable
{
private int currentPageIndex;
private IList<Stream> streams;
private DataTable LoadSalesData()
{
// Create a new DataSet and read sales data file
// data.xml into the first DataTable.
DataSet dataSet = new DataSet();
// See https://github.com/elastic/elasticsearch-net/issues/2860
public class MyDocument
{
public string RecordType { get; set; }
}
var client = new ElasticClient();
client.Search<MyDocument>(s => s
@bozhink
bozhink / stop-telemetry.ps1
Created September 9, 2017 19:55
PowerShell: turn off Telemetry in Windows10
Stop-Service DiagTrack
Set-Service DiagTrack -StartupType Disabled
@bozhink
bozhink / npoisi.cs
Created August 11, 2017 07:43
NPOI Summary Information
/// See https://stackoverflow.com/questions/11143303/how-to-set-author-name-to-excel-file-using-poi
public static void SetAuthor(this IWorkbook workbook, string author)
{
if (workbook is NPOI.XSSF.UserModel.XSSFWorkbook)
{
var xssfWorkbook = workbook as NPOI.XSSF.UserModel.XSSFWorkbook;
var xmlProps = xssfWorkbook.GetProperties();
var coreProps = xmlProps.CoreProperties;
coreProps.Creator = author;
return;