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 / GenerateCookieControllerProgramaticallyLogin.cs
Created October 11, 2017 11:54
Generates a new cookie for the client i.e. programatically login. This works in the normal MVC. Or when you change the role of the current user.
// usings
using Microsoft.Owin;
using Microsoft.AspNet.Identity.Owin
using Microsoft.AspNet.Identity;
using System.Security.Claims;
using System.Web;
using System.Web.Mvc;
using WebApplication.Web.App_Start; // Application managers
private const string RoleName = "Administrator"
@M-Yankov
M-Yankov / Instructions.md
Created September 8, 2017 12:16
Web Config Transformation

To set the transformation to work

This document describes how to set transform config XML on Build in Visual Studio without using any Extensions

  • The .csproj file will be modified.
  • WebProject.csproj to see which modifications are required.
  1. It could begin from the web.config
  2. Right click on it and select Add Config Transforms
  3. This will make web.Config parent of web.Debug.Config and web.Release.Config
  4. Unload .csproj file and edit it.
@M-Yankov
M-Yankov / FormData.js
Created August 11, 2017 20:50
Using FormData that works in internet explorer and file upload !
var IEFormData = new FormData();
$divForm.find('input[name], textarea[name]')
.each(function(i, el) {
var val = $(el).val();
if (!val) {
return;
}
if (el.type && el.type === 'file') {
for (var i = 0; i < el.files.length; i++) {
@M-Yankov
M-Yankov / imageResponse.js
Created August 11, 2017 20:34
How return raw image data from node js
// This gist shows how to return raw image data
// Of Course depends how the image is stored in the database.
// The image upload functionallity is implemented with `multer` library and directly stored in mongodb (not good practice, but...)
return res.end(images[0].buffer.buffer);
@M-Yankov
M-Yankov / CsvExport.cs
Last active February 25, 2017 19:56
Do not use var
/* The code is get from project */
protected void btnExportCSV_Click(object sender, EventArgs e)
{
//Get List of all AnimalData from DAL as a List object
var listAnimalData = AdminMCCDAL.GetActiveAnimalData(); // !!!!
if (listAnimalData.Count > 0)
{
//Export this list of AnimalData to a .CSV file
listAnimalData.ExportCSV("MCC_AnimalIntakesExport");
@M-Yankov
M-Yankov / SampleAsync.cs
Created November 23, 2016 08:25
Sample async example.
private async Task<string> Execute()
{
// Keep watching for out of memory exception when using new string
string text = "First Line" + Environment.NewLine + "Second" + Environment.NewLine + new string('-', int.MaxValue / 33);
text += text;
StringReader reader = new StringReader(text);
Console.WriteLine("=Before=");
string readText = await reader.ReadLineAsync();
@M-Yankov
M-Yankov / cmdCommand.txt
Created October 24, 2016 11:56
CMD Build C# Solution
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE>devenv.exe "C:\Users\mihkov\Desktop\McDInsights-A-Triks-VPN\Mc
DInsights-A-Triks-VPN\Source\McDInsights\McDInsights.sln" /build Debug
Source: https://msdn.microsoft.com/en-us/library/b20w810z.aspx
@M-Yankov
M-Yankov / RefreshUIWPF.cs
Created September 24, 2016 22:03
WPF refresh UI
public static class ExtensionMethods
{
private static Action EmptyDelegate = delegate() { };
public static void Refresh(this UIElement uiElement)
{
uiElement.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);
}
@M-Yankov
M-Yankov / StepsToGenerateCoverage.md
Created September 4, 2016 18:25
Steps to generate a test coverage results using VS integrated testing framework.

This instructions applies to upload your test coverage to coveralls.io

Using Coveleralls .NET package and Visual Studio 2015 Enterprise

  1. Create Unit test project. Click Analyze Code Coverage from main menu in Visual Studio.
  2. Check TestResults folder in root directory of your project. Find .coverage file.
  • (If you don't use VS 2015 Enterprice check:
    vstest.console.exe /inIsolation /Enablecodecoverage YourTestProject.dll and find the output .coverage file)
  1. Execute following command: "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" analyze /output:coverage.coveragexml C:\PathToYourCoverage.coverage
@M-Yankov
M-Yankov / ConsoleColors.cpp
Created July 16, 2016 13:22
C++ console colors
// color your text in Windows console mode
// colors are 0=black 1=blue 2=green and so on to 15=white
// colorattribute = foreground + background * 16
// to get red text on yellow use 4 + 14*16 = 228
// light red on yellow would be 12 + 14*16 = 236
// a Dev-C++ tested console application by vegaseat 07nov2004
#include <iostream>
#include <windows.h> // WinApi header