InternetException

design patterns

design patterns · 7 posts (all tags)

Integrating my AI assistant with StartPage

· 673 words · ~3 min read · in AI

#design patterns

Today I was fixing an issue with my assistant having a hard time accessing web search . I fixed that but I was not entirelly satisfied with the result. Browsh is great for that used but I am using StartPage on my PC and on my phone. Ability to see similar or even the same web search result for me and my assistant would be great.

How hard it can be to actually fetch the result od search via CLI? Actually it is not that hard. I was able to figurę it out though it requires very specific set od parameters, headers being sent to very specific address.

Read the whole thing →

Pattern matching

· 103 words · ~1 min read · in .NET, interview

#design patterns #SOLID #C#

Pattern matching is used for: testing expression to check if some value have certain characteristics safer compare because ‘==’ and ‘!=’ can be overloaded Examples: a is int number sequence is IList<T> list switch statement: command switch { Operation.SystemTest => RunDiagnostics(), Operation.Start => StartSystem(), Operation.Stop => StopSystem(), Operation.Reset => ResetToReady(), _ => throw new ArgumentException("Invalid enum value for command", nameof(command)), }; switch with ranges: tempInFahrenheit switch { (> 32) and (< 212) => "liquid", < 32 => "solid", > 212 => "gas", 32 => …

Read the whole thing →

Asynchronous programming in .NET

· 46 words · ~1 min read · in .NET, interview

#async #design patterns

Asynchronous programming patterns in .NET: Asynchronous Programming Model (BeginOperation/EndOperation) Event-based Asynchronous Pattern (invoke event with result from async job) Task-based Asynchronous Pattern (Task<>) Ways of achieving asynchronous code in .NET async, await Task class API (Run, WhenAll, WhenAny, etc.) ThreadPool.QueueUserWorkItem(ThreadProc); Further read: async/await in .NET https://learn.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/

IDisposable interface pattern

· 218 words · ~1 min read · updated · in .NET, interview

#design patterns

Example implementation of IDisposable

public class MyResource : IDisposable
{
    public MyResource(IntPtr handle)
    {
        this.handle = handle;
    }

    public void Dispose()
    {
        Dispose(disposing: true);
        GC.SuppressFinalize(this);
    }

    protected virtual void Dispose(bool disposing)
    {
        if(!this.disposed)
        {
            if(disposing)
            {
                component.Dispose();
            }

            CloseHandle(handle);
            handle = IntPtr.Zero;
            disposed = true;
        }
    }

    ~MyResource()
    {
        Dispose(disposing: false);
    }
}

MyResource object have pointer which is unmanaged. This is why this class should implement IDisposable interface. Implementation should be correct according to recommended pattern (see below for documentation).

There a re few points to highlight here:

Read the whole thing →

Xamarin Master-Detail Page

· 5408 words · ~27 min read · updated · in .NET, C#

#XAML #design patterns #Xamarin

This article as previous ones (Frame With Padding , Frame Outline Problem , Inheritance from Implicit Styles ) also will be about Xamarin. This time we will inspect Master-Detail page control/mechanism. You can find official documentation for this control here . Quick spoiler: I never used this in any production application. Why? I will explain. Whole article will be to explain why this is just not worth your time. In this and subsequent articles I will introduce much better solution.

Read the whole thing →