Skip to content

Instantly share code, notes, and snippets.

@Flayed
Flayed / TimedProcessor.cs
Created March 11, 2018 17:18
TimedProcesor
public class TimedProcessor
{
/// <summary>
/// Times the TimedProcessor has fired its Elapsed function
/// </summary>
public int TimesElapsed { get; set; }
/// <summary>
/// Indicates whether or not the TimedProcessor is running
/// </summary>
@Flayed
Flayed / MyDataSetAccess.cs
Created March 3, 2018 13:08
Query/Project from List
public async Task<bool> IsLocationInUse(string setId, string country, string state, CancellationToken cancellationToken = default)
{
bool isLocationInUse = await MySetCollection.Aggregate()
.Match(x => x.SetId == setId)
.Project(Builders<MyDataSet>.Projection
.Include("Attributes.State")
.Include("Attributes.Country")
.Exclude("_id"))
.Unwind("Attributes")
.Match(new BsonDocument { { "Attributes.State", state }, { "Attributes.Country", country } })
@Flayed
Flayed / MyDataSet.cs
Created March 3, 2018 13:02
Mongo DB dataset with a list
public class MyDataSet
{
public string SetId { get; set; }
public string Name { get; set; }
public List<Attributes> Attributes { get; set; }
}
public class Attributes
{
public string State { get; set; }
@Flayed
Flayed / MongoDelete.cs
Created February 14, 2018 20:05
Mongo Delete
public class MongoDelete()
{
private MongoClient Client = new MongoClient("mongodb://connectionString");
private IMongoDatabase Db = Client.GetDatabase("MyDatabaseName");
private IMongoCollection<MyEntity> Collection = Db.GetCollection<MyEntity>("MyCollection");
public async Task Delete(string key, int id)
{
await Collection.UpdateOneAsync(x => x.Key == key && x.Items.Any(i => i.Id == id),
@Flayed
Flayed / MongoUpdate.cs
Created February 14, 2018 19:53
Mongo Update
public class MongoUpdate()
{
private MongoClient Client = new MongoClient("mongodb://connectionString");
private IMongoDatabase Db = Client.GetDatabase("MyDatabaseName");
private IMongoCollection<MyEntity> Collection = Db.GetCollection<MyEntity>("MyCollection");
public async Task Update(string key, int id, MyEntityItem newEntityItem)
{
await Collection.UpdateOneAsync(x => x.Key == key && x.Items.Any(i => i.Id == id),
@Flayed
Flayed / MongoRead.cs
Created February 14, 2018 19:50
Mongo Read
public class MongoRead()
{
private MongoClient Client = new MongoClient("mongodb://connectionString");
private IMongoDatabase Db = Client.GetDatabase("MyDatabaseName");
private IMongoCollection<MyEntity> Collection = Db.GetCollection<MyEntity>("MyCollection");
public async Task<IEnumerable<MyEntityItem>> Read(string key)
{
var cursor = await Collection.FindAsync(x => x.Key == key).ConfigureAwait(false);
@Flayed
Flayed / MongoCreate.cs
Created February 14, 2018 19:46
Mongo Create (Add)
public class MongoCreate()
{
private MongoClient Client = new MongoClient("mongodb://connectionString");
private IMongoDatabase Db = Client.GetDatabase("MyDatabaseName");
private IMongoCollection<MyEntity> Collection = Db.GetCollection<MyEntity>("MyCollection");
public async Task Add(string key, params MyEntityItem[] items)
{
await Collection.UpdateOneAsync(x => x.Key == key,
@Flayed
Flayed / MyEntity.cs
Created February 14, 2018 19:39
Mongo Data Structure
[BsonIgnoreExtraElements]
public class MyEntity
{
public string Key { get; set; }
public List<MyEntityItem> Items { get; set; } = new List<MyEntityItem>();
}
public class MyEntityItem
{
public string Name { get; set; }
@Flayed
Flayed / d3-mouseclick.ts
Created February 1, 2018 19:58
D3 and this
// Typescript
svg.on("click", () => {
const coords = d3.mouse(svg.node());
console.log(coords);
});
// Typescript
svg.on("click", () => {
const coords = d3.mouse(d3.event.currentTarget);
console.log(coords);
@Flayed
Flayed / d3-mouseclick.js
Created February 1, 2018 19:16
D3 and this
// Javascript
svg.on("click", function() {
var coords = d3.mouse(this);
console.log(coords);
});