Skip to content

Instantly share code, notes, and snippets.

View deepumi's full-sized avatar
🎯
Focusing

Deepu Madhusoodanan deepumi

🎯
Focusing
View GitHub Profile
@deepumi
deepumi / Extensions.cs
Last active August 16, 2019 17:19
HttpStatus code enum -> int & string
using static System.Net.HttpStatusCode;
internal static class Extensions
{
internal static string AsString(this HttpStatusCode status) => status switch
{
Continue => nameof(Continue),
SwitchingProtocols => nameof(SwitchingProtocols),
Processing => nameof(Processing),
EarlyHints => nameof(EarlyHints),
@deepumi
deepumi / Logger.cs
Created August 13, 2019 14:23
Logging class for CLI tools!
internal sealed class Logger : ILogger
{
private readonly FileStream _writer = new FileStream(Config.Configuration["LogFile"], FileMode.Create, FileAccess.Write,
FileShare.None, 1024, FileOptions.SequentialScan);
private readonly UTF8Encoding _utf = new UTF8Encoding(true);
private readonly byte[] _line;
internal Logger() => _line = _utf.GetBytes(Environment.NewLine);
@deepumi
deepumi / Sample.ps1
Created August 5, 2019 13:39
Powershell sample
([system.reflection.assembly]::loadfile("")).FullName
@deepumi
deepumi / PropertySetter.cs
Created June 18, 2019 14:41
Poco property setter using Expressions tress.
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
internal sealed class PropertySetter<T>
{
private const BindingFlags Flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase;
private readonly Type _type = typeof(T);
@deepumi
deepumi / Sort.cs
Last active June 14, 2019 13:39
Insertion Sort
string[] arr = { "orange", "nest", "apple", "ABC","xyz", "bana", "cat"};
for (int i = 0; i < arr.Length; i++)
{
for (int j = i + 1; j < arr.Length; j++)
{
if (arr[i]?.CompareTo(arr[j]) > 0)
{
var temp = arr[j];
arr[j] = arr[i];
@deepumi
deepumi / StaticThreadySafety.cs
Last active May 14, 2019 12:58
Thready safety in Static Variables
//Interlocked class Provides atomic operations for variables that are shared by multiple threads.
private static string _data;
public ActionResult Index()
{
//Compares two instances of the specified reference type <paramref name="T" /> for equality and, if they are equal, replaces the first one
if (Interlocked.CompareExchange(ref _data, "test", null) == null)
{
@deepumi
deepumi / feature.cs
Last active December 22, 2018 15:11
Feature flag
using System;
using System.Collections.Concurrent;
namespace FeatureFlagTest
{
class Program
{
static void Main(string[] args)
{
var home = new HomeController(FeatureFactory.Feature);
@deepumi
deepumi / TypeActivator.cs
Last active August 1, 2018 20:04
Create instance using Reflection
public static class TypeActivator<T>
{
private delegate T Activator<T>(params object[] args);
private static readonly Dictionary<string, Activator<T>> _items = new Dictionary<string, Activator<T>>();
/// <summary>
///
/// </summary>
/// <returns></returns>
public static T Create()
@deepumi
deepumi / sample.go
Created April 23, 2018 01:05
Go samples
//main.go
package main
import (
"fmt"
"time"
"awesomeProject/another"
)
@deepumi
deepumi / StripMarkupTags.cs
Created March 29, 2018 13:39
Strip Html Markup Tags
private static string StripMarkupTags(string source)
{
if (source == null) return string.Empty;
var length = source.Length;
var array = new ArrayBuilder(length);
var markup = false;
for (var i = 0; i < length; i++)
{