Skip to content

Instantly share code, notes, and snippets.

View M-Yankov's full-sized avatar
💻
🤖🧭🏃‍♂️🚵‍♂️

Mihail Yankov M-Yankov

💻
🤖🧭🏃‍♂️🚵‍♂️
View GitHub Profile
@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 / 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 / DownloadHtmlAsImage.js
Last active January 8, 2019 22:32
Download Html AS image png html2canvas
/* Test on Firefox 64.0
* See https://html2canvas.hertzen.com/
* https://github.com/niklasvh/html2canvas/
*
* Usage:
* Open a page
* Open developer console (F12)
* Paste the script below
* Click save image.
*
@M-Yankov
M-Yankov / todoist_task_export.js
Created January 1, 2019 16:46
Export tasks from todoist page. Open todoist.com, load tasks and execute the following script:
var listItems = [];
document.querySelectorAll('.task_item')
.forEach(e => listItems.push(e.textContent) )
listItems.join('\n');
// Regex separate year labels (\w+)([0-9]{4})
@M-Yankov
M-Yankov / colorful-scrollbar.as.css
Last active January 9, 2020 04:27 — forked from Sporif/dark-scrollbar.as.css
Dark scrollbar for Firefox 57. Tested on Windows 10. Requires https://gist.github.com/Sporif/db6b3440fba0b1bcf5477afacf93f875
scrollbar, scrollbar *:not(scrollbarbutton), scrollcorner {
-moz-appearance: none !important;
--scrollbar-width: 15px;
--scrollbar-height: var(--scrollbar-width);
}
scrollbar, scrollcorner {
background: #fff !important;
}
scrollbar[orient="vertical"] {
@M-Yankov
M-Yankov / select2cacheResults.js
Last active October 16, 2019 05:34
select2 dropdown: When loading results with ajax, load them once. (the results are always the same)
var s2data = $allUnitsSelect.select2({
ajax: {
url: '/GetValues',
dataType: 'json',
data: function (params) {
var query = {
text: text,
}
return query;
@M-Yankov
M-Yankov / DoNotBlockUIThread.cs
Created May 3, 2018 14:32
How to not block the UI thread
/* How to not block UI thread: */
public static void Main()
{
/* Your code here */
Task exitTask = ExitCommandAsync();
Task.WaitAll(exitTask);
/* Console remains active */
}
@M-Yankov
M-Yankov / EntityFramworkExceptions.cs
Created February 25, 2018 13:37
The entity framework exceptions (.NET)
(ex as System.Data.Entity.Validation.DbEntityValidationException).EntityValidationErrors.ToList()[0].ValidationErrors.ToList()[0]
@M-Yankov
M-Yankov / LoaderBootstrap.html
Created November 26, 2017 23:16
Width loader
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<style>
@M-Yankov
M-Yankov / DynamicModel.cs
Created November 3, 2017 13:10
How to get all properties from a dynamic model.
dynamic person = new object { Name = "John", Age = 32, Title = "HR" };
// In case the person comes from somewhere else
if (person != null)
{
var properties = person.GetType().GetPtoperties(); // Will return an Array of System.Reflection.PropertyInfo[];
// or
Type theType = (Type)person.GetType();