Skip to content

Instantly share code, notes, and snippets.

View Scooletz's full-sized avatar

Szymon Kulec Scooletz

View GitHub Profile
@Scooletz
Scooletz / ArraySegmentTest.cs
Last active August 29, 2015 14:10
ArraySegment possible to use with SqlCommand
[Test]
public void TestChunks()
{
const string connectionString = @"YOUR_DB";
const string insertEvent = "INSERT INTO Events (id, payload) VALUES(@id, @payload)";
const int testSize = 10;
using (var con = new SqlConnection(connectionString))
{
@Scooletz
Scooletz / gist:9b78bd52451f76ba0eea
Created April 23, 2015 12:19
nullable alignment
public class TestX
{
[Test]
public void T()
{
Inspect(typeof(int));
Inspect(typeof(long));
Inspect(typeof(bool));
Inspect(typeof(Guid));
}
@Scooletz
Scooletz / EntityAwareModelBinder.cs
Created May 21, 2011 06:33
EntityAwareModelBinder to be used with NHibernate
/// <summary>
/// The model binder aware of entities types.
/// </summary>
/// <remarks>
/// If an action parameter is an entity, it uses custom binding,
/// searching for already existing (if id provided) and applying changes onto it.
///
/// The binder does not cascade onto entities' properties which are references to the other entities.
/// All it does is one level (for entity->entity relationships) mapping.
/// </remarks>
@Scooletz
Scooletz / ActionInvoker.cs
Created May 24, 2011 21:25
ActionProviders
using System.Web.Mvc;
namespace ActionProviders
{
/// <summary>
/// The extended controller actions invoker, using other than controllers action providers.
/// </summary>
public class ActionInvoker : ControllerActionInvoker
{
private readonly IActionProvider[] _actionProviders;
@Scooletz
Scooletz / ActionInfo.cs
Created June 18, 2011 11:39
CRUD action provider
/// <summary>
/// The class representing an action info, with its <see cref="ActionMethodSelectorAttribute"/> retrieved.
/// </summary>
/// <remarks>
/// For performance optimization, cache this class instances.
/// </remarks>
public sealed class ActionInfo
{
private readonly ActionMethodSelectorAttribute[] _attributes;
remote="$1"
url="$2"
z40=0000000000000000000000000000000000000000
IFS=' '
while read local_ref local_sha remote_ref remote_sha
do
if [ "$local_sha" = $z40 ]
then
@Scooletz
Scooletz / ExceptionBasedLogEnhancer.cs
Last active December 16, 2015 04:39
log4net enhancement for adding exception into to log4net, especially EventLog based appender. View http://blog.scooletz.com/2013/04/15/enhancing-log4net-exception-logging for more information
using System;
using log4net.Core;
using log4net.Filter;
using log4net.Util;
namespace Log4NetEnhancing
{
public class ExceptionBasedLogEnhancer : FilterSkeleton
{
private const string EventLogKeyEventId = "EventID";
@Scooletz
Scooletz / JS module (AMD & standard)
Created June 24, 2013 21:18
This is a snippet of a nice introducing modules to your js code.
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD is found. Use it to register as anonymous module.
define(['jquery'], factory);
} else {
// AMD is not found, use a standard module patter
factory(jQuery);
}
}(function ($) {
// use $ safetly, it's provided either by AMD or a simple module patter
@Scooletz
Scooletz / MeasureTimeAttribute.cs
Created July 28, 2013 15:53
A simple way of wrapping a test in a time measuring scope.
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class MeasureTimeAttribute : Attribute, ITestAction
{
private const string Key = "stopWatch";
public void BeforeTest(TestDetails testDetails)
{
TestContext.CurrentContext.Test.Properties[Key] = Stopwatch.StartNew();
}
@Scooletz
Scooletz / CodeCopPossibleBug.cs
Last active March 2, 2016 06:48
Both tests don't work. When a struct is turned into a class, they start to work
using System;
using CodeCop.Core;
using CodeCop.Core.Fluent;
using NUnit.Framework;
namespace CodeCop.Tests
{
public class CodeCopStructBugTests
{
public unsafe struct WithPtr