Skip to content

Instantly share code, notes, and snippets.

Avatar

Dĵ ΝιΓΞΗΛψΚ dj-nitehawk

View GitHub Profile
@dj-nitehawk
dj-nitehawk / Program.cs
Created September 14, 2022 10:53
endpoint grouping with fastendpoints
View Program.cs
using FastEndpoints;
using FastEndpoints.Swagger;
var builder = WebApplication.CreateBuilder();
builder.Services.AddFastEndpoints();
builder.Services.AddSwaggerDoc(tagIndex: 0);
var app = builder.Build();
app.UseAuthorization();
app.UseFastEndpoints();
@dj-nitehawk
dj-nitehawk / Program.cs
Created November 1, 2021 04:22
fast-endpoints: trigger event from anywhere
View Program.cs
global using FastEndpoints;
var builder = WebApplication.CreateBuilder();
builder.Services.AddFastEndpoints();
var app = builder.Build();
app.UseAuthorization();
app.UseFastEndpoints();
Task.Run(async () =>
@dj-nitehawk
dj-nitehawk / Program.cs
Last active July 9, 2021 06:03
full watcher example
View Program.cs
using MongoDB.Bson;
using MongoDB.Entities;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace TestApplication
{
public static class Program
@dj-nitehawk
dj-nitehawk / Program.cs
Created July 7, 2021 15:40
nested lookup example
View Program.cs
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Entities;
using System.Threading.Tasks;
namespace ReferencedRelationshipExample
{
public class Author : Entity
{
public string Name { get; set; }
@dj-nitehawk
dj-nitehawk / Run.cs
Created July 7, 2021 03:52
async over sync wrapper
View Run.cs
public static class Run
{
private static bool IsDotNetFx =>
RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework", StringComparison.OrdinalIgnoreCase);
private static readonly TaskFactory factory =
new TaskFactory(
CancellationToken.None,
TaskCreationOptions.None,
TaskContinuationOptions.None,
@dj-nitehawk
dj-nitehawk / Program.cs
Last active April 21, 2021 05:25
fuzzy text search with sorted results
View Program.cs
using MongoDB.Entities;
using System.Linq;
using System.Threading.Tasks;
namespace TestApplication
{
public static class Program
{
public class Item : Entity
{
@dj-nitehawk
dj-nitehawk / Program.cs
Last active July 27, 2021 16:19
update by incrementing field
View Program.cs
using MongoDB.Entities; //https://mongodb-entities.com
using System;
using System.Threading.Tasks;
namespace TestApplication
{
public class Message : Entity
{
public string Content { get; set; }
public int Upvotes { get; set; }
@dj-nitehawk
dj-nitehawk / Program.cs
Created March 30, 2021 15:16
SCRAM-SHA-1 auth method
View Program.cs
var username = "user";
var password = "password";
MongoInternalIdentity internalIdentity = new("auth_db_name", username);
PasswordEvidence passwordEvidence = new(password);
MongoCredential mongoCredential = new("SCRAM-SHA-1", internalIdentity, passwordEvidence);
await DB.InitAsync("DatabaseName", new MongoClientSettings
{
Server = new MongoServerAddress("localhost", 27017),
@dj-nitehawk
dj-nitehawk / Program.cs
Last active March 31, 2021 09:51
advanced query injection
View Program.cs
using MongoDB.Entities;
using System;
using System.Text;
using System.Threading.Tasks;
namespace TestApplication
{
public class UserActivity : Entity
{
public string RawUrl { get; set; }
@dj-nitehawk
dj-nitehawk / Program.cs
Created February 5, 2021 15:05
resume token demo for watcher/change-stream
View Program.cs
using MongoDB.Bson;
using MongoDB.Entities;
using System;
using System.IO;
using System.Threading.Tasks;
namespace TestApplication
{
public class Book : Entity
{