Skip to content

Instantly share code, notes, and snippets.

View marisks's full-sized avatar

Māris Krivtežs marisks

View GitHub Profile
@marisks
marisks / Sample.cs
Last active December 9, 2023 13:35
Improved Jimmy Bogard's ValueObject<T> which supports inheritance
// Ordinary
public class SimpleDto : ValueObject<SimpleDto>
{
public string Value { get; set; }
}
// With base class
public abstract class BaseDto<T> : ValueObject<T>
{
public string BaseValue { get; set; }
@marisks
marisks / ServiceApiSmokeTests.cs
Last active March 18, 2016 16:26
EPiServer Service API smoke tests
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Xunit;
@marisks
marisks / CreatedAndModifiedDateInterceptor.cs
Created February 27, 2016 06:46
Entity Framework soft delete, modiefied and created date interceptors
using System;
using System.Data.Entity.Core.Common.CommandTrees;
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.Infrastructure.Interception;
using System.Linq;
public class CreatedAndModifiedDateInterceptor : IDbCommandTreeInterceptor
{
public const string CreatedColumnName = "Created";
public const string ModifiedColumnName = "Modified";
module WebApi2Helpers
// Port of answer by @nikosbaxevanis :- http://stackoverflow.com/a/19954215/11635
open System
open Ploeh.AutoFixture
open Ploeh.AutoFixture.Kernel
open Ploeh.AutoFixture.Xunit
open Ploeh.AutoFixture.AutoFoq
open System.Web.Http.Hosting
@marisks
marisks / EPi_WebApi_DI
Last active August 29, 2015 14:05
EPiServer WebAPI dependency injection configuration
[ModuleDependency(typeof(ServiceContainerInitialization))]
[InitializableModule]
public class DependencyResolverInitialization : IConfigurableModule
{
public void ConfigureContainer(ServiceConfigurationContext context)
{
context.Container.Configure(ConfigureContainer);
GlobalConfiguration.Configuration.Routes.MapHttpRoute(
name: "DefaultApi",
@marisks
marisks / appDblText
Last active August 29, 2015 13:56
AngularJS input text field with read mode as span and editing with double click.
// usage: <app-dbl-text ng-model="model.name"></app-dbl-text>
app.directive('appDblText', function ($compile, $parse) {
return {
restrict: 'E',
template: '<div><span></span><input type="text" ng-model="ngModel" class="form-control" style="display:none;"></div>',
replace: true,
link: function(scope, elem, attrs) {
var model = attrs.ngModel;
var spans = elem.find('span');
var inputs = elem.find('input');
@marisks
marisks / backup.ps1
Last active June 13, 2018 05:10
Backup RavenDB all DBs by providing tenants in parameter. Works with PowerShell 2. For usage see backup_dbs.ps1 and restore_dbs.ps1 Original script works only with PowerShell 3: http://ravendb.net/kb/46/backing-up-all-databases-using-powershell
param(
[parameter(Mandatory=$true)]
[string]
$ravenUrl,
[parameter(Mandatory=$true)]
[string]
$backupDir,
[parameter(Mandatory=$true)]
[string]
$ravenBackupTool,
@marisks
marisks / CacheHelper.cs
Created February 2, 2013 12:03
Static class to simplify work with ASP.NET Cache.
public static class CacheHelper
{
/// <summary>
/// Returns cache value or default(T) if no value in cache
/// </summary>
/// <typeparam name="T">Type of cached value</typeparam>
/// <param name="key">Cache key for cached value</param>
/// <returns>Cached value</returns>
public static T Get<T>(string key)
{