Skip to content

Instantly share code, notes, and snippets.

View hidegh's full-sized avatar

balazs HIDEGHETY hidegh

View GitHub Profile
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web.Http.Metadata;
using System.Web.Http.Validation;
using System.Web.Http.Validation.Providers;
using System.Web.Http.Validation.Validators;
namespace My.Web.Code.Binder
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web.Mvc;
namespace My.Web.Code.Binder
{
/// <summary>
/// Inside Global.asax:
/// <summary>
/// Usage: [JsonConverter(typeof(JsonDateTimeConverter), "MM\\/dd\\/yyyy")].
/// Dates created/set in JS had time-zones appended. By using string, this issue won't persist...
/// </summary>
public class JsonDateTimeConverter : DateTimeConverterBase
{
private string CustomFormat { get; }
public JsonDateTimeConverter(string customFormat)
{
public static TransactionScope New(TransactionScopeOption transactionScopeOption = TransactionScopeOption.Required, IsolationLevel isolationLevel = IsolationLevel.ReadCommitted, TimeSpan? timeout = null)
{
// NOTE: this is a fix, to avoid inner transaction timeout's to shorten the outer one...
if (Transaction.Current != null && transactionScopeOption == TransactionScopeOption.Required)
timeout = TimeSpan.FromMinutes(15);
var options = new TransactionOptions
{
IsolationLevel = isolationLevel,
Timeout = timeout ?? TransactionManager.DefaultTimeout
//
// COMMON DLL
//
public interface IStatusCode
{
int? StatusCode { get; set; }
}
public static class IStatusCodeEx
import {NgControl} from "@angular/forms";
import {Directive, ElementRef} from "@angular/core";
@Directive({
selector: '[ngModel]', // or 'input, select, textarea' - but then your controls won't be handled and also checking for undefined would be necessary
})
export class NativeElementInjectorDirective {
constructor(private el: ElementRef, private control : NgControl) {
(<any>control.control).nativeElement = el.nativeElement;
}
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNet.OData;
using Microsoft.AspNet.OData.Extensions;
using Microsoft.AspNet.OData.Query;
using System.Linq;
using System;
using Newtonsoft.Json;
namespace R.Web.Api
@hidegh
hidegh / ExpressionInitialParameterRenamer.cs
Last active December 29, 2018 20:01
"Unifies" the expression, so we get same result if same expression is used (with different base parameter name)...
using System;
using System.Linq.Expressions;
/// <summary>
/// Usage:
/// var exp1 = (Expression<Func<Person, string>>) exp1 = i => i.Addresses[0].City;
/// var exp2 = (Expression<Func<Person, string>>) exp1 = j => j.Addresses[0].City;
/// var exp1String = new ExpressionInitialParameterRenamer().Rename(exp1).ToString();
/// /// </summary>
namespace ExpressionHelper
@hidegh
hidegh / toggle-classes.js
Created July 30, 2019 07:43
Allows to toggle/add/remove classes of an HTML element...
$(document).on('click', '[data-toggle="class"]', function () {
var $target = $($(this).data('target'));
var toggleClasses = $(this).data('toggle-classes');
if (toggleClasses)
$target.toggleClass(toggleClasses);
var addClass = $(this).data('add-classes');
if (addClass)
$target.addClass(addClass);
@hidegh
hidegh / ProcessEx.cs
Created February 27, 2020 09:36
Process with redirected input/output/error streams (async) supporting timeout...
using System;
using System.Diagnostics;
using System.IO;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace R
{