Skip to content

Instantly share code, notes, and snippets.

View mishrsud's full-sized avatar
🎯
Focusing

Sudhanshu Mishra mishrsud

🎯
Focusing
View GitHub Profile
@mishrsud
mishrsud / HostedService.cs
Created November 5, 2018 03:29 — forked from davidfowl/HostedService.cs
A base class that allows writing a long running background task in ASP.NET Core 2.0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
namespace WebApplication24
{
public abstract class HostedService : IHostedService
using Microsoft.Azure.CosmosDB.Table;
namespace AzureTableStorageDemo
{
public class ChildrenEntity : TableEntity
{
public ChildrenEntity()
{
}
-- Technique 1
SELECT CASE transaction_isolation_level
WHEN 0 THEN 'Unspecified'
WHEN 1 THEN 'ReadUncommitted'
WHEN 2 THEN 'ReadCommitted'
WHEN 3 THEN 'RepeatableRead'
WHEN 4 THEN 'Serializable'
WHEN 5 THEN 'Snapshot' END AS TRANSACTION_ISOLATION_LEVEL
FROM sys.dm_exec_sessions
where session_id = @@SPID
@mishrsud
mishrsud / LimitedPool{T}.cs
Created March 6, 2018 03:45
Creates a limited number of IDisposable objects - useful to manage e.g. HttpClient instances in a object pool. Ref: https://pastebin.com/jftEbWrc
public class LimitedPool<T> : IDisposable where T : class
{
readonly Func<T> _valueFactory;
readonly Action<T> _valueDisposeAction;
readonly TimeSpan _valueLifetime;
readonly ConcurrentStack<LimitedPoolItem<T>> _pool;
bool _disposed;
public LimitedPool(Func<T> valueFactory, Action<T> valueDisposeAction, TimeSpan? valueLifetime = null)
{
@mishrsud
mishrsud / UnixyfyPath.cs
Created March 4, 2018 23:46
Converts a Windows path to Unix path that can be used from WSL (Windows Subsystem for Linux)
var path = @"C:\SourceCode\docker-test-framework\Core\app.config";
var cdriveRepl = string.Concat("/", "mnt", "/", "c", "/");
var unixPathSep = "/";
Console.WriteLine(path.Replace(@"C:\", cdriveRepl).Replace(@"\", unixPathSep));
// From https://github.com/shanselman/get-azure/blob/master/Program.cs
public static class ShellHelper
{
public static string Bash(string cmd)
{
var escapedArgs = cmd.Replace("\"", "\\\"");
var process = new Process()
{
StartInfo = new ProcessStartInfo
void Main()
{
var jobExecutor = new JobExecutor();
Task t = Task.Run(() => jobExecutor.DoJob());
t.ConfigureAwait(false);
Task t2 = Task.Run(() => jobExecutor.DoJob());
t2.ConfigureAwait(false);
void Main()
{
var str = "Hello";
var integer = 23;
System.Reflection.MethodInfo methodDefinition = typeof(GenericClass).GetMethod("PrintName");
System.Reflection.MethodInfo method = methodDefinition.MakeGenericMethod(integer.GetType());
method.Invoke(new GenericClass(), new object [] {integer});
}
// Define other methods and classes here
@mishrsud
mishrsud / kebase.md
Created February 4, 2018 07:51
My Keybase proof for github

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@mishrsud
mishrsud / findArrayInArray.js
Created December 21, 2017 20:07
JavaScript array of arrays
function arrayTest() {
var array = [
[1234, "123123-132131-ejwh213", "comment 1234 | comment 2345"],
[1235, "123124-132132-ejwh214", "comment 3 | comment 32"],
[1236, "1231235132133-ejwh215", "comment 4 | comment 5"]];
var theArray = array.find(function (el) {
return el.indexOf("1231235132133-ejwh215") > -1;
});