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 / 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 / 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 / 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]