Skip to content

Instantly share code, notes, and snippets.

View 0x414c49's full-sized avatar
💪
Coding!

Ali Bahrami 0x414c49

💪
Coding!
  • ValueBlue B.V
  • Utrecht, The Netherlands
View GitHub Profile
@0x414c49
0x414c49 / sample1.csx
Created December 19, 2019 10:26
C# Scripting sample1
using System;
using System.IO;
var today = DateTime.Now.ToString();
var message = $"Hello World, This file is created at {today}";
// Some fancy comment here
class Foo
{
@0x414c49
0x414c49 / sample2.csx
Created December 19, 2019 11:07
CSharp scripting example with referencing examle
// You need to reference your Assembly dlls file like this
#r "Newtonsoft.Json.dll"
using System;
using Newtonsoft.Json;
class Product
{
public Guid Id{get;set;}
@0x414c49
0x414c49 / sample3.csx
Created December 19, 2019 11:22
CSharp scripting with nuget referencing.
// Make sure you define the version of Nuget package for caching!
#r "nuget: Newtonsoft.Json, 12.0.3"
using System;
using Newtonsoft.Json;
class Product
{
@0x414c49
0x414c49 / sample4.csx
Created December 19, 2019 13:16
Script-CS example
using System;
using Newtonsoft.Json;
class Product
{
public Guid Id{get;set;}
public string Name{get;set;}
public bool Enabled{get;set;}
}
@0x414c49
0x414c49 / Program.cs
Created December 23, 2019 13:58
Memory Sample1
class Program
{
static void Main(string[] args)
{
LongStringConcatWithStringBuilder();
//LongStringConcat();
var bytes = GC.GetTotalMemory(false); // for getting memory used by GC
Console.WriteLine("Bytes consumed: {0}", bytes);
}
@0x414c49
0x414c49 / SampleMemory2.cs
Created December 23, 2019 15:21
Memory Leak
public class Foo
{
private JobQueue _jobQueue;
private Guid _uniqeId;
public Foo(JobQueue jobQueue)
{
_jobQueue = jobQueue;
}
@0x414c49
0x414c49 / weakref.cs
Created December 23, 2019 15:46
WeakReference.cs
class Program
{
static WeakReference _weakStringBuilder =
new WeakReference(new StringBuilder());
static void Main(string[] args)
{
if (_weakStringBuilder.IsAlive)
Console.WriteLine("Alive");
GC.Collect();
@0x414c49
0x414c49 / Program.cs
Created January 2, 2020 13:27
CLI example01
using McMaster.Extensions.CommandLineUtils;
using System;
using System.IO;
namespace CSVUtil
{
class Program
{
public static void Main(string[] args)
{
var inputFileOption = app.Option<string>("-i|--input", "Input file to convert"
, CommandOptionType.SingleValue)
.IsRequired();
var verboseOption = app.Option("-v|--verbose", "Display operation details"
, CommandOptionType.NoValue);
@0x414c49
0x414c49 / Program-2.cs
Last active January 2, 2020 13:48
CLI 2
#region convert-command
app.Command("convert",
(convert) =>
{
var outputOption = convert.Option("-o|--output", "Output File"
, CommandOptionType.SingleValue);
var firstRowOption = convert.Option("-f|--first-row-header", "First row as header"
, CommandOptionType.NoValue);