Skip to content

Instantly share code, notes, and snippets.

View ayende's full-sized avatar

Ayende Rahien ayende

View GitHub Profile
public void Add(T item){
lock(m_lock){
_container.Add(item);
Monitor.PulseAll(m_lock);
}
}
declare function SourceAccountIsValid(src, dst, req){
}
declare function SourceAccountHasFunds(src, dst, req){
}
declare function validate_transfer(src, dst, req){
var rules = [SourceAccountIsValid, SourceAccountHasFunds,
SourceAccountDailyLimitNotExceed, DestinationAccountHasNoLiens,
DestinationAccountMaxAmountNotExceeded, MoneyTransferIsNotFromDirtyBitcoins
];
var errors = rules.map(rule=> rule(src, dst, req).filter(x=>x!= null);
public async Task SendMoney(SendMoneyRequest req)
{
var srcAccount = await _accountRepository.LoadAsync(req.SourceAccount);
var dstAccount = await _accountRepository.LoadAsync(req.DesinationAccount);
Guard.Null(srcAccount, "Source account must exists");
Guard.Null(dstAccount, "Destination account must exists");
var rules = _transferValidationRules.GetAll();
var state = new TranfserValidationState();
public async Task SendMoney(SendMoneyRequest req)
{
var srcAccount = await _accountRepository.LoadAsync(req.SourceAccount);
var dstAccount = await _accountRepository.LoadAsync(req.DesinationAccount);
Guard.Null(srcAccount, "Source account must exists");
Guard.Null(dstAccount, "Destination account must exists");
var rules = _transferValidationRules.GetAll();
foreach(var rule in rules)
var dic = new Dictionary<string, int> { ["A"] = 0, ["B"] = 0, ["C"] = 0 };
for (int i = 0; i < 10_000; i++)
{
var list = new List<string> { "A", "B", "C" };
list.Sort((x, y) => new Random().Next(0, 2));
dic[list[0]]++;
}
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#if WIN32
#define strdup _strdup
#endif
struct val;
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#if WIN32
#define strdup _strdup
#endif
struct val;
@ayende
ayende / lodus.c
Last active February 26, 2020 08:15
Simple object manipulation library that leaks memory and needs a GC
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#if WIN32
#define strdup _strdup
#endif
struct val;
@ayende
ayende / good.cs
Last active February 14, 2020 10:23
[Route("/public/api/v1/tickets/{org}")]
public async Task<IActionResult> Get(string org, int skip = 0)
{
var tickets = await session.Query<Domain.SupportTicket>()
.Where(x=>x.Organization == org)
.OrderByDescending(x => x.LastUpdate)
.Skip(skip)
.Select(ticket => new PublicTicketDto
{
Subject = ticket.Subject,
@ayende
ayende / bad.cs
Last active February 14, 2020 10:17
[Route("/public/api/v1/tickets/{org}")]
public async Task<IActionResult> Get(string org, int skip = 0)
{
var tickets = await session.Query<Domain.SupportTicket>()
.Where(x=>x.Organization == org)
.OrderByDescending(x => x.LastUpdate)
.Skip(skip)
.ToListAsync();
return Ok(tickets);