This file contains 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
class Person(object): | |
def __init__(self, name, age): | |
self.name = name | |
self.age = age | |
self.Id = None | |
document_store = documentstore("http://live-test.ravendb.net", "Census") | |
document_store.initialize() | |
This file contains 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 interface ITrie | |
{ | |
// Try to add the key/val to the trie | |
// can fail if there isn't enough room | |
// if already exists, will overwrite old | |
// value | |
bool TryWrite(string key, long value); | |
// Try to find the key in the trie, if found, | |
// will put the value in the out param. |
This file contains 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
// map | |
from order in docs.Orders | |
from line in order.Lines | |
select new { | |
Product = line.Product, | |
Total = ((line.Quantity * line.PricePerUnit) * (1 - line.Discount)) | |
} | |
// reduce | |
from result in results |
This file contains 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
def ReplicateTo(remoteServerUrl): | |
socket = WebSocketConnectionTo(remoteServerUrl +"/replication") | |
lastEtag = socket.RPC("What is your last etag from me?") | |
while true: | |
hasDocs = false; | |
for doc in GetDocumentsAfter(lastEtag): | |
lastEtag = doc.Etag |
This file contains 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 wait = new ManualResetEventSlim(); | |
wait.Set(); | |
database.Notifications.OnDocumentChanged += change => | |
{ | |
if(this.Collections.Contains(change.CollectionName)) | |
wait.Set(); | |
}; | |
while(database.ShutdownCancellationToken.IsCancellationRequested == false) | |
{ | |
wait.Wait(database.ShutdownCancellationToken); |
This file contains 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 wait = new ManualResetEventSlim(); | |
wait.Set(); | |
database.Notifications.OnDocumentChanged += change => | |
{ | |
if(this.Collections.Contains(change.CollectionName)) | |
wait.Set(); | |
}; | |
while(database.ShutdownCancellationToken.IsCancellationRequested == false) | |
{ | |
wait.Wait(database.ShutdownCancellationToken); |
This file contains 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
from result in results select new { | |
InsertDate=result.InsertDate==null?default(DateTime):result.InsertDate==null?0:System.DateTime.Parse(result.InsertDate.ToString()), | |
PropertyType=result.PropertyType==null?default(object):result.PropertyType.Value==null?null:(result.PropertyType.Value.GetType()==typeof(Raven.Abstractions.Linq.DynamicList)?(result.PropertyType.Value.FirstOrDefault()==null?null:result.PropertyType.Value.FirstOrDefault().ToString()) :result.PropertyType.Value), | |
AgriculturalPropertyType=result.AgriculturalPropertyType==null?default(object):result.AgriculturalPropertyType.Value==null?null:(result.AgriculturalPropertyType.Value.GetType()==typeof(Raven.Abstractions.Linq.DynamicList)?(result.AgriculturalPropertyType.Value.FirstOrDefault()==null?null:result.AgriculturalPropertyType.Value.FirstOrDefault().ToString()) :result.AgriculturalPropertyType.Value), | |
TransactionType=result.TransactionType==null?default(object):result.TransactionType.Value==null?null:(result.TransactionType.Value.GetType()== |
This file contains 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 bool TryAllocate(sbyte size, out ushort pos) | |
{ | |
pos = 0; | |
// we use one byte for the size | |
if( _header->LastAllocation + size + 1 > 32*1024) | |
return false; | |
pos = _header->LastAllocation + 1; | |
_header->LastAllocation+=size +1; | |
_header->SpaceUsed+=size+1; | |
_mem[pos - 1] = size;// size marker |
This file contains 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 int JumpConsistentHash(ulong key, int numBuckets) | |
{ | |
ulong choosenBucket = ulong.MaxValue; | |
ulong index = 0; | |
while (index < (ulong) numBuckets) | |
{ | |
choosenBucket = index; | |
key = key * 2862933555777941757UL + 1; | |
index = (ulong)((choosenBucket + 1) * (double)(1L << 31) / (key >> 33) + 1); | |
} |
This file contains 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 class SingleProducerSingleConsumerCircularQueue | |
{ | |
const int QueueSize = 256; | |
volatile int _readPos, _writePos; | |
private readonly byte[][] _data = new byte[QueueSize][]; | |
int PositionToArrayIndex(int pos) | |
{ | |
return pos % QueueSize; |