Skip to content

Instantly share code, notes, and snippets.

View M-Yankov's full-sized avatar
💻
Driven by functionality, not by design

Mihail Yankov M-Yankov

💻
Driven by functionality, not by design
View GitHub Profile
@M-Yankov
M-Yankov / UseTwoAsyncMethods.cs
Last active February 27, 2019 21:12
The correct way two invoke two async methods
public class Program
{
public static async Task Main(string[] args)
{
Stopwatch timer = Stopwatch.StartNew();
Task a = OperationSlow();
Task b = OperationFast();
await Task.Delay(5000);
@M-Yankov
M-Yankov / GetServiceFromScope.cs
Last active March 30, 2019 13:28
Get services from scope with IWebHost
// ASP Net Core 2.2.2
// Get registered services from WebHost instance.
// In case the IServiceCollection or ApplicationBuilder is not available in the current context.
// The method can be used in separate assembly
pulbic void TestMethod()
{
using (IServiceScope scope = this.webHost.Services.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
RoleManager<IdentityRole> roleManager = scope.ServiceProvider.GetRequiredService<RoleManager<IdentityRole>>();
@M-Yankov
M-Yankov / MSBuildFilePublish.txt
Created April 18, 2019 13:15
Local File Publish with MS Build
msbuild ProjectFile.csproj /p:Configuration=Release ^
/p:Platform=AnyCPU ^
/t:WebPublish ^
/p:WebPublishMethod=FileSystem ^
/p:DeleteExistingFiles=True ^
/p:publishUrl=c:\output
msbuild Solution.sln /p:Configuration=Release ^
/p:DeployOnBuild=True ^
/p:DeployDefaultTarget=WebPublish ^
@M-Yankov
M-Yankov / GetAddressMemory.cs
Created September 9, 2019 06:13
Returns the address of the memory refferensed by object.
public unsafe void Get(MyModel a)
{
System.Runtime.InteropServices.GCHandle handle = System.Runtime.InteropServices.GCHandle.Alloc(a, System.Runtime.InteropServices.GCHandleType.Weak);
try
{
IntPtr pointer = System.Runtime.InteropServices.GCHandle.ToIntPtr(handle);
string test = "0x" + pointer.ToString("X");
}
finally
{
@M-Yankov
M-Yankov / App.Config
Created September 18, 2019 22:26
A sample C# .NET CORE app using PredicateBuilder.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="LocalDb" connectionString="Data Source=LENOVO-G710;Initial Catalog=PredicateBuilder;Integrated Security=True" providerName=""/>
</connectionStrings>
</configuration>
@M-Yankov
M-Yankov / PdfGenerator.cs
Last active January 14, 2020 11:13
A code that generates a PDF document for testing (requires iTextSharp)
using System;
using System.IO;
using iText.Kernel.Colors;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
public class Program
{
@M-Yankov
M-Yankov / cmd.md
Created November 7, 2021 06:31
Andtoid export/backup database

Connect the phone

execute the following line in CMD as Administrator

cd "C:\Program Files (x86)\Android\android-sdk\platform-tools"
adb backup -f C:\Users\M.Yankov\Desktop\data.ab com.mihyan.simpletracker

In the phone screen Enable dubug if asked

@M-Yankov
M-Yankov / Article.md
Created February 24, 2022 19:15
An article for my blog

When working with nullable booleans and using null condiional operator could be wrong:

Let's take the follwoing example:
bool? isRecording = savedInstanceState?.GetBoolean("isRecording");

if (isRecording) - This won't compile. need another approach. The condition if (isRecording == false) will be true when the variable is equal to false and when it is null. It's logical to work like that since the default value of bool is false and the null value is more suitable to false. But we should be careful if the logic need to be executed only if it's equal to false.

@M-Yankov
M-Yankov / bike-shops-list.md
Last active March 4, 2022 15:21
Bike shop sites
  • Basebike
  • allmountain
  • niko bikes
  • hala bikes
  • pumpmybike.eu
  • 1001parts
  • veloserviz.com
  • bikeshop-bg.com
  • champion-bikeshop.com
  • pavebikeshop
@M-Yankov
M-Yankov / RaceEventSites.md
Last active February 26, 2025 21:03
A web sites of events for trail running or bike