Skip to content

Instantly share code, notes, and snippets.

View jasmin-mistry's full-sized avatar
🏠
Working from home

Jasmin Mistry jasmin-mistry

🏠
Working from home
  • London, United Kingdom
View GitHub Profile
@jasmin-mistry
jasmin-mistry / Program.cs
Created September 22, 2022 22:01
String Width & Alignment
var number = 1;
new List<string>
{
$"|{number}|", // |1|
$"|{number, -10}|", // |1 |
$"|{number, 10}|" // | 1|
}.ForEach(Console.WriteLine);
@jasmin-mistry
jasmin-mistry / ComputerNetwork.cs
Created September 22, 2022 21:27
Computer Network Algorithm test
public static class ComputerNetwork
{
public static void Run()
{
//var output = Network(new int[] { 0, 3, 4, 2, 6, 3 }, new int[] { 3, 1, 3, 3, 3, 5 });
var output = Network(new int[] { 0, 4, 2, 2, 4 }, new int[] { 1, 3, 1, 3, 5 });
//var output = Network(new int[] { 0, 4, 4, 2, 7, 6, 3 }, new int[] { 3, 5, 1, 3, 4, 3, 4 });
Console.WriteLine($"output is : {output}");
}
@jasmin-mistry
jasmin-mistry / Program.cs
Created September 22, 2022 21:24
Stop Watch C#
using System.Diagnostics;
var stopWatch = new Stopwatch();
stopWatch.Start();
//Tasks.Run();
var ts = stopWatch.Elapsed;
// Format and display the TimeSpan value.
@jasmin-mistry
jasmin-mistry / Program.cs
Created September 22, 2022 21:23
ContainsDuplicates C#
using System.Diagnostics;
List<int> numbers = new() { 1,2,3,4,3,5};
if (ContainsDuplicates(numbers))
{
Console.WriteLine("Contains Duplicate? Yes");
}
else
{
@jasmin-mistry
jasmin-mistry / row count all tables.sql
Created January 27, 2022 10:35
Row count for all tables in a SQL database
DECLARE @QueryString NVARCHAR(MAX) ;
SELECT @QueryString = COALESCE(@QueryString + ' UNION ALL ','')
+ 'SELECT '
+ '''' + QUOTENAME(SCHEMA_NAME(sOBJ.schema_id))
+ '.' + QUOTENAME(sOBJ.name) + '''' + ' AS [TableName]
, COUNT(*) AS [RowCount] FROM '
+ QUOTENAME(SCHEMA_NAME(sOBJ.schema_id))
+ '.' + QUOTENAME(sOBJ.name) + ' WITH (NOLOCK) '
FROM sys.objects AS sOBJ
@jasmin-mistry
jasmin-mistry / aqara_magic_cube_blueprint.yaml
Created April 19, 2021 13:35
Aqara Magic Cube Blueprint - Home Assistant
blueprint:
name: Aqara Magic Cube
description: Control anything using Aqara Magic Cube.
domain: automation
input:
remote:
name: Magic Cube
description: Select the Aqara Magic Cube device
selector:
device:
@jasmin-mistry
jasmin-mistry / ExceptionFilterUtility.cs
Created November 29, 2020 20:40
A New Pattern for Exception Logging
public static class ExceptionFilterUtility
{
public static bool True(Action action)
{
action();
return true;
}
public static bool False(Action action)
{
@jasmin-mistry
jasmin-mistry / recursive test.cs
Created April 7, 2020 14:34
recursive test c#
[Test]
public void Test()
{
var str = "{\"start\":123,\"rows\":213,\"query\":{\"$eq\":[\"template\",\"Catalogue Allocation\"]},\"parentQuery\":{\"4\":{\"$eq\":[\"recordid\",\"65570\"]}}}";
//var m = Regex.Matches(str,"\"(?<key>[^\"]+)\"\\s*:\\s*(?:\"([^\"]+)\"|(?<value>\\d+)),?", RegexOptions.IgnoreCase);
//var startGroup = m.FirstOrDefault(x => x.Success && x.Value.Contains("\"start\""));
//var rowsGroup = m.FirstOrDefault(x => x.Success && x.Value.Contains("\"rows\""));
//if (startGroup != null && rowsGroup != null)
@jasmin-mistry
jasmin-mistry / ActivatorExt.cs
Last active January 12, 2020 13:30
Invoke generic method dynamically at runtime
public static class ActivatorExt
{
private static ObjectActivator<T> GetActivator<T>(ConstructorInfo ctor)
{
var paramsInfo = ctor.GetParameters();
var param = Expression.Parameter(typeof(object[]), "args");
var argsExp = new Expression[paramsInfo.Length];
@jasmin-mistry
jasmin-mistry / ActivatorExt.cs
Created January 12, 2020 13:15
Create Instance for a generic type with arguments for constructor
public static class ActivatorExt
{
private static ObjectActivator<T> GetActivator<T>(ConstructorInfo ctor)
{
var paramsInfo = ctor.GetParameters();