Skip to content

Instantly share code, notes, and snippets.

balazs HIDEGHETY hidegh

View GitHub Profile
@hidegh
hidegh / ProcessEx.cs
Created Feb 27, 2020
Process with redirected input/output/error streams (async) supporting timeout...
View ProcessEx.cs
using System;
using System.Diagnostics;
using System.IO;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace R
{
@hidegh
hidegh / toggle-classes.js
Created Jul 30, 2019
Allows to toggle/add/remove classes of an HTML element...
View toggle-classes.js
$(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 / ExpressionInitialParameterRenamer.cs
Last active Dec 29, 2018
"Unifies" the expression, so we get same result if same expression is used (with different base parameter name)...
View ExpressionInitialParameterRenamer.cs
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
View AspNetCoreCustomODataQueryAttribute.cs
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
View NativeElementInjectorDirective-For-Angular2-TemplateDriven-FormControls.ts
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;
}
View ExceptionWithStatusAndMessageCode.cs
//
// COMMON DLL
//
public interface IStatusCode
{
int? StatusCode { get; set; }
}
public static class IStatusCodeEx
View TransactionScope.cs
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
View hangfire-notification-attribute.cs
/// <summary>
/// Depends on domain events...
/// Reason: wanted to de-couple it from the next job and so I do have DI objects accessible...
///
/// NOTE:
/// This is by default a PERMANENT failure notification filter, since the filter Order is so high, it get's surely executed after the AutomaticRetry filter.
/// Also if AutomaticRetry filter does delete the job on permanent fail, the PERMANENT failure notification won't occure.
///
/// If the HangfirePermanentFailureNotificationEvent.Order is less than the AutomaticRetry.Order, we will get a notification on each failure, not just the last one!
/// </summary>
View JsonDateTimeConverter.cs
/// <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)
{
View MvcDataAnnotationsModelValidatorProviderWithDependencyResolverSupport.cs
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:
You can’t perform that action at this time.