Skip to content

Instantly share code, notes, and snippets.

View ayende's full-sized avatar

Ayende Rahien ayende

View GitHub Profile
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()
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.
// 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
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
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);
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);
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()==
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
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);
}
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;