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 / 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 / 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 / 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 / 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 / AttibutesOnGetSet.cs
Created October 11, 2017 12:01
In C# you can set an attribute to the setter. It works in normal .NET 4.5
// Extracted from System.Web
public IPrincipal User
{
get
{
return this._principalContainer.Principal;
}
[SecurityPermission(SecurityAction.Demand, ControlPrincipal=true)]
set
{
@M-Yankov
M-Yankov / EventAddRemove.cs
Created October 11, 2017 13:34
Event property has add/remove instead of get/set
public event EventHandler AuthenticateRequest
{
add
{
this.AddSyncEventHookup(HttpApplication.EventAuthenticateRequest, value, RequestNotification.AuthenticateRequest);
}
remove
{
this.RemoveSyncEventHookup(HttpApplication.EventAuthenticateRequest, value, RequestNotification.AuthenticateRequest);
}
@M-Yankov
M-Yankov / TernaryOperatorReadable.cs
Created October 12, 2017 19:59
It seems that the following syntax for nested ternary operators is the most readable (for me);
return
<First_Expression> ? "Value1" :
<Second_Expression> ? "Value2" :
<Third_Expression> ? "Value3":
"Value4"; // And so on....
@M-Yankov
M-Yankov / FixUtcDateOnClient.js
Created October 19, 2017 15:04
Fxing the UTC dates on client side
/*
This script will work only on the client-side
*/
function toClientDate(dateText) {
if (!validateInput(dateText)) {
return '';
}
var date = new Date(dateText);
@M-Yankov
M-Yankov / PasteXMLasCSharpClasses.md
Last active October 20, 2017 11:48
An instructions to add XML structure as C# code

How to add an XML structered code to C# classes.

  1. copy a valid XML code
<items>
  <item>
    <title>
      Lorem ipsum 2017-10-19T13:55:00+00:00
 
@M-Yankov
M-Yankov / AsyncCode.cs
Created October 27, 2017 13:58
How to execute something asynchronous
var taskArray = new Task[tasksCount];
for (int index = 0; index < taskArray.Length; index++)
{
var productId = productIds[index];
var task = Task.Run(() => UpdatePoductStatus(productId, Status.Available));
taskArray[index] = task;
}
Task.WaitAll(taskArray);