This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var semaphore = new SemaphoreSlim(5); | |
var pending = 0; | |
Action onCompleted = () => Interlocked.Decrement(ref pending); | |
for (var i = 0; i < 20; i++) { | |
await semaphore.WaitAsync(); | |
Interlocked.Increment(ref pending); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int n = 1000000; | |
int intMax = 2147483647; | |
int chunkSize = intMax/n; | |
int resultIndex = 0; | |
int[] result = new int[n]; | |
int lower = 0; | |
int currentChunkSize = chunkSize; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int n = 1000000; | |
int intMax = 2147483647; | |
int k = intMax/n; | |
int resultIndex = 0; | |
int[n] result; | |
for (int i = 0; i < n; i++) { | |
double normalized = rand()/(double) RAND_MAX; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Asynchronous version of <see cref="AutoResetEvent" /> | |
/// </summary> | |
public sealed class AutoResetEventAsync { | |
private static readonly Task<bool> Completed = Task.FromResult(true); | |
private readonly ConcurrentQueue<TaskCompletionSource<bool>> handlers = | |
new ConcurrentQueue<TaskCompletionSource<bool>>(); | |
private int isSet; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class Program { | |
private static void Main(string[] args) { | |
using (var documntStore = new DocumentStore {Url = "http://localhost:8080", DefaultDatabase = "test", Credentials = new NetworkCredential("<user>","<password>")}.Initialize()) | |
using (var bulk = documntStore.BulkInsert()) { | |
bulk.Report += Console.WriteLine; | |
for (var i = 0; i < 80000000; i++) { | |
bulk.Store(new MyItem | |
{ | |
Hash = Guid.NewGuid().ToString("N") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using FluentNHibernate; | |
using FluentNHibernate.Automapping; | |
using FluentNHibernate.Cfg; | |
using FluentNHibernate.Cfg.Db; | |
using NHibernate.Linq; | |
using Environment = NHibernate.Cfg.Environment; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static long FindPosition(Stream stream, byte[] bytes) { | |
var buffer = new byte[Math.Max(1024, bytes.Length)]; | |
if (buffer.Length == 0) | |
return -1; | |
while (true) { | |
var count = stream.Read(buffer, 0, buffer.Length); | |
if (count < bytes.Length) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace ConsoleApplication1 | |
{ | |
internal class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
var idents = new[] {1, 2, 3, 4, 5, 6, 7}; | |
var index = 0; | |
using (var documentStore = new EmbeddableDocumentStore {UseEmbeddedHttpServer = true}.Initialize()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[EsentTempPathInUseException: Temp path already used by another database instance] | |
Microsoft.Isam.Esent.Interop.Api.Check(Int32 err) in C:\Work\ravendb\SharedLibs\Sources\managedesent-61618\EsentInterop\Api.cs:2739 | |
Microsoft.Isam.Esent.Interop.Api.JetInit(JET_INSTANCE& instance) in C:\Work\ravendb\SharedLibs\Sources\managedesent-61618\EsentInterop\Api.cs:131 | |
Raven.Storage.Esent.TransactionalStorage.Initialize(IUuidGenerator uuidGenerator, OrderedPartCollection`1 documentCodecs) in c:\Builds\RavenDB-Unstable-v2.0\Raven.Database\Storage\Esent\TransactionalStorage.cs:302 | |
[InvalidOperationException: Could not open transactional storage: C:\RavenDB\Web\RavenData\Data] | |
Raven.Storage.Esent.TransactionalStorage.Initialize(IUuidGenerator uuidGenerator, OrderedPartCollection`1 documentCodecs) in c:\Builds\RavenDB-Unstable-v2.0\Raven.Database\Storage\Esent\TransactionalStorage.cs:317 | |
Raven.Database.DocumentDatabase..ctor(InMemoryRavenConfiguration configuration) in c:\Builds\RavenDB-Unstable-v2.0\Raven.D |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Task Save(IEnumerable<MyEntity> entities, CancellationToken cancellationToken) { | |
return Task.Factory.StartNew(() => { | |
foreach (var batch in Batch(entities, 20)) { | |
cancellationToken.ThrowIfCancellationRequested(); | |
this.documentStore.DatabaseCommands.Batch( | |
from entity in batch | |
select new PutCommandData { | |
Document = RavenJObject.FromObject(entity), | |
Key = entity.Id, |
NewerOlder