What is a practical way to model lookup tables in Domain Driven Design (DDD)?

You may want to look into the concept of Command Query Separation. I wouldn’t worry about typed repositories for lookup values, but I’d still probably use DTO type classes over datasets etc… You may want to spend some time reading Greg Young’s blogs starting from this one to the present. He doesn’t talk about filling … Read more

How to get the Country according to a certain IP? [duplicate]

There are two approaches: using an Internet service and using some kind of local list (perhaps wrapped in a library). What you want will depend on what you are building. For services: http://www.hostip.info/use.html (as mentioned by Mark) http://www.team-cymru.org/Services/ip-to-asn.html For lists: http://www.maxmind.com/app/geoip_country (as mentioned by Orion) You could roll your own by downloading the lists from … Read more

Lookup Tables Best Practices: DB Tables… or Enumerations

Generally you should only use enumeration where there is a clear set of items that will not change, e.g. primary colours, or continent names. Otherwise lookup tables with appropriately implemented foreign keys are pretty much always the best option. There is a possible variation on the lookup table option where you potentially have a large … Read more

Mongodb Join on _id field from String to ObjectId

You can use $toObjectId aggregation from mongodb 4.0 which converts String id to ObjectId db.role.aggregate([ { “$lookup”: { “from”: “user”, “let”: { “userId”: “$_id” }, “pipeline”: [ { “$addFields”: { “userId”: { “$toObjectId”: “$userId” }}}, { “$match”: { “$expr”: { “$eq”: [ “$userId”, “$$userId” ] } } } ], “as”: “output” }} ]) Or you … Read more

What’s an appropriate search/retrieval method for a VERY long list of strings?

using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Security.Cryptography; namespace HashsetTest { abstract class HashLookupBase { protected const int BucketCount = 16; private readonly HashAlgorithm _hasher; protected HashLookupBase() { _hasher = SHA256.Create(); } public abstract void AddHash(byte[] data); public abstract bool Contains(byte[] data); private byte[] ComputeHash(byte[] data) { return _hasher.ComputeHash(data); } protected Data256Bit GetHashObject(byte[] … Read more

Fast computing of log2 for 64-bit integers

Intrinsic functions are really fast, but still are insufficient for a truly cross-platform, compiler-independent implementation of log2. So in case anyone is interested, here is the fastest, branch-free, CPU-abstract DeBruijn-like algorithm I’ve come to while researching the topic on my own. const int tab64[64] = { 63, 0, 58, 1, 59, 47, 53, 2, 60, … Read more