Skip to content

Instantly share code, notes, and snippets.

View darkiri's full-sized avatar

Kirill Davletkildeev darkiri

View GitHub Profile
@darkiri
darkiri / gist:2039990
Created March 14, 2012 22:17
is there a method which returns all .net base types/structs that System.Convert is able to convert to/from?
typeof (Convert)
.GetMethods(BindingFlags.Static|BindingFlags.Public)
.Where(m=>m.Name.StartsWith("To"))
.Select(m=>m.GetParameters().First().ParameterType)
.Distinct()
@darkiri
darkiri / gist:3078953
Created July 9, 2012 21:11
Optimistic Concurrency in RavenDB
[Subject("Raven Experiments")]
public class when_updating_same_object_in_separate_sessions : raven_persistence_context
{
static Exception Exception;
Establish context = () => StoreSingleObject(new MyClass {Text = "this one"});
Because of = () => Exception = Catch.Exception(UpdateTwoObjectsInTwoSessions);
It should_throw_concurrency_exception = () => Exception.ShouldBeOfType<ConcurrencyException>();
static void UpdateTwoObjectsInTwoSessions()
@darkiri
darkiri / gist:3079035
Created July 9, 2012 21:22
Optimistic Concurrency in RavenDB
[Subject("Raven Experiments")]
public class when_storing_two_objects_with_same_id_in_separate_sessions : raven_persistence_context
{
static Exception Exception;
Because of = () => Exception = Catch.Exception(CreateTwoObjectsInTwoSessions);
It should_throw_concurrency_exception = () => Exception.ShouldBeOfType<ConcurrencyException>();
static void CreateTwoObjectsInTwoSessions()
{
@darkiri
darkiri / gist:3100418
Created July 12, 2012 19:39
Optimistic Concurrency MongoDB
[Subject("Mongo")]
public class when_issuing_an_update_on_a_changed_entity : mongo_context
{
private static long DocumentsAffected;
private Establish context = () => SetUpDatabase();
private Because of = () => DocumentsAffected = UpdateSameObjectTwice();
private It should_not_affect_any_documents = () => Assert.That(DocumentsAffected, Is.EqualTo(0));
private static long UpdateSameObjectTwice()
@darkiri
darkiri / gist:3100444
Created July 12, 2012 19:44
Optimistic Concurrency MongoDB
var events = db.GetCollection("events");
events.Insert(new Event {Id = "1", Payload = 2});
events.Insert(new Event {Id = "1", Payload = 3}, SafeMode.True);
@darkiri
darkiri / MigratableObject.cs
Created April 30, 2013 06:44
Some ideas for MongoDB schema migrations using ISupportInitialize (based on https://github.com/darkiri/mongo-csharp-migrations)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
namespace MongoDB.Migrations
{
public class MigratableObject : ISupportInitialize
{
@darkiri
darkiri / scala-school-questions.md
Last active October 24, 2018 16:58 — forked from adnanced/scala-school-questions.md
Scala school questions
  • Scala syntax 5 questions - should be enough (?), there are question for beginner, intermediate and more advanced stuff. If not enough, more possible themes: type tags, dependent types...
    • How well do you know Option/Try/Either types from Scala standard library?
      • I heard about them, but I don't see clear benefits
      • I use them and understand the benefits, but I struggle with them
      • I fully understand why we use them and have no problems with them
    • How do you get and combine values from those types mentioned above?
      • I don't
      • I use map/flatMap most of the time
  • I try using for-comprehension most of the time