Skip to content

Instantly share code, notes, and snippets.

View nitinjs's full-sized avatar
🥳
God takes care those who care

Nitin Sawant nitinjs

🥳
God takes care those who care
View GitHub Profile
@nitinjs
nitinjs / defer
Last active March 31, 2023 18:25
golang defer keyword alternative in C#
//Author: Nitin Sawant
//add reference to AspectInjector package https://github.com/pamidur/aspect-injector
using AspectInjector.Broker;
using System.Reflection;
DeferTest test = new DeferTest();
test.Test();
public class DeferTest
@nitinjs
nitinjs / cloudSettings
Last active February 22, 2019 19:27
Visual Studio Code Settings Sync Gist
{"lastUpload":"2019-02-21T11:58:08.359Z","extensionVersion":"v3.2.5"}
@nitinjs
nitinjs / CombinePdf.cs
Created October 6, 2018 06:57
Using iTextSharp combines two template files into one pdf and adds table to the pages
//iTextSharp
using (FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "TableTest.pdf", FileMode.Create))
{
Document doc = new Document(PageSize.LETTER);
doc.SetMargins(0, 0, 0, 0);
PdfWriter writer = PdfWriter.GetInstance(doc, fs);
doc.Open();
//add first page
PdfReader pdfReader = new PdfReader(templatePath + "Page1.pdf");
@nitinjs
nitinjs / LineParser.cs
Created September 28, 2018 08:43
Generic class to parse pipe separated text into object
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
public class LineParser<T> where T : class
@nitinjs
nitinjs / Parallel.cs
Created September 27, 2018 10:22
Processing large number of items in parallel
//Task Parallel library dataflow can be obtained by nuget: https://www.nuget.org/packages/System.Threading.Tasks.Dataflow/
var watch = new System.Diagnostics.Stopwatch();
watch.Start();
Action<int> an = n => {
//add your processing logic here
Console.WriteLine(n);
};
var options = new ExecutionDataflowBlockOptions
@nitinjs
nitinjs / GetDevicePPI.cs
Created September 25, 2018 06:39
Allows to get device ppi in C#
class Program
{
[DllImport("gdi32.dll")]
static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
[DllImport("user32.dll")]
static extern IntPtr GetDC(IntPtr hWnd);
/// <summary>
/// Logical pixels inch in X