Thinker
Thinker
CC#
Created by Thinker on 12/11/2023 in #help
✅ Authenticating using OAuth
Does anyone have any resources on authenticating using OAuth? I wanna interact with the Google Workspaces APIs which require OAuth authentication, but I have no idea how to properly set it up. I have the OAuth2 client secret and ID set up, I'm just unsure of how to use it.
58 replies
CC#
Created by Thinker on 11/23/2023 in #help
✅ Installing .NET on Ubuntu
So just installed .NET on Ubuntu through Snap, and am getting this warning
An issue was encountered verifying workloads. For more information, run "dotnet workload update".
An issue was encountered verifying workloads. For more information, run "dotnet workload update".
and when running dotnet workload update
Unhandled exception: System.IO.IOException: Read-only file system : '/snap/dotnet-sdk/228/metadata'
Unhandled exception: System.IO.IOException: Read-only file system : '/snap/dotnet-sdk/228/metadata'
idk what to do to solve this
28 replies
CC#
Created by Thinker on 10/28/2023 in #help
✅ Implementing Tarjan's strongly connected components algorithm
So I'm trying to implement Tarjan's strongly connected components algorithm, an algorithm for generating strongly connected components from a graph. I already have a graph (a list of nodes), and I've tried to implement the algo, but it does not work as intended. And yes I'm using a struct to keep track of data associated with the nodes, sue me. https://paste.mod.gg/odfzzxyybahk/0
7 replies
CC#
Created by Thinker on 9/27/2023 in #help
✅ Copy files generated by command to build output
During a build, I want to run a command to build a Vue project which outputs its files to a folder, then copy the files from that folder to a wwwroot folder in the project's build output. How would I do this? I know I can use Exec to run the command which works fine, but I don't know how I would copy the files properly while preserving the subfolder structure.
57 replies
CC#
Created by Thinker on 9/25/2023 in #help
✅ What's the point of MediatR?
I haven't done a lot of web/API dev, so this might just be because I've never been in a situation where I've actually needed it, but what is the point of MediatR? I don't really understand it too well, so if someone could give me a rundown, that would be incredible.
128 replies
CC#
Created by Thinker on 6/17/2023 in #help
❔ Parsing JSON value with multiple different possibilities
I have a JSON object which can take on one of two different structures
"name": {
"first": "John",
"last": "Smith"
}
// or
"name": "John Smith"
"name": {
"first": "John",
"last": "Smith"
}
// or
"name": "John Smith"
How would I go about parsing this into an object using STJ? Assume the object to deserialize to is this
record Person(Name Name);
record Name(string First, string Last);
record Person(Name Name);
record Name(string First, string Last);
27 replies
CC#
Created by Thinker on 5/19/2023 in #help
❔ Default command in System.CommandLine
I'm using System.CommandLine for a little CLI, and I want two commands: compile and run. What I want is for the user to be able to just do myapp path/to/some.file which would invoke compile by default, but also be able to do myapp run path/to/some.file, in a similar vein to how dotnet path/to/some.file is just dotnet exec path/to/some.file. How do you do this?
25 replies
CC#
Created by Thinker on 5/3/2023 in #help
✅ Thread-safe list
I'm trying to turn a piece of code which just calls a list of tasks asynchronous. Each of these tasks writes to a List<T> passed to all the tasks. I'm using Task.WhenAll to run all the tasks in parallel, however I'm unsure of whether using a regular List<T> is fine or if I should be using something else.
3 replies
CC#
Created by Thinker on 5/2/2023 in #help
✅ Allowing option of using dependency injection
I'm working on a small-ish project, mostly for personal use. I have a 'core' type called ILazyGenerator and a corresponding ILazyGeneratorBuilder type, both with 'default' concrete implementations in the same project. These default concrete types or interface don't inherently provide any support for dependency injection, but in the slim case that someone else who maybe eventually possibly perhaps is going to use my library wants dependency injection, I might want to support that. However, I really want to keep this initial project relatively small and simple, and not have to bring in huge packages like MS.Ext.DI. So there are two possibilities I'm considering: either I have the interfaces a mess of generics which provide support for generic context objects everywhere, or I just bite the bullet and include standard support for DI using MS.Ext.DI in the base library. Obviously the latter is easily the simpler of the two, however I still would like some feedback.
12 replies
CC#
Created by Thinker on 5/1/2023 in #help
❔ ✅ Is middleware considered a pattern?
I'm working on a little toy project, and I want to implement a kind of "middleware" into it. However, other than ASP.NET, I'm having a hard time finding resources about implementing middleware as a pattern. Is middleware considered a "pattern", or is it just something that exists in ASP.NET and not really anywhere else else? Are there any decent resources about implementing it into applications?
20 replies
CC#
Created by Thinker on 4/20/2023 in #help
✅ 0-1 sine wave
Just a super general math question. If I want a sine wave which has a period of 1 and an amplitude of 1 which goes between 0 and 1, what would be the most concise way to write that? I.e. f(0) = 0, f(0.5) = 1, f(1) = 0, as a sine wave.
35 replies
CC#
Created by Thinker on 4/10/2023 in #help
❔ Best way to display a continually updating list of messages
@inject MerpieClient Client
@inject MerpieHubConnection HubConnection
@inject ILogger<MessageList> Logger

<div class="flex flex-col-reverse gap-y-4">
@foreach (var message in messages)
{
<MessageDisplay Message="message"/>
}
</div>

@code {

private readonly List<MessageDto> messages = new();

protected override async Task OnInitializedAsync()
{
await HubConnection.StartConnection();

HubConnection.OnMessageSent += OnMessageSent;
HubConnection.OnMessageDeleted += OnMessageDeleted;
HubConnection.OnMessageEdited += OnMessageEdited;

// Fetch messages
if (await Client.GetMessages() is ApiResult<IEnumerable<MessageDto>>.Success success)
messages.AddRange(success.Value);
}

private void OnMessageSent(MessageDto message)
{
Logger.LogInformation("Message with ID {id} received", message.Id);

messages.Insert(0, message);
StateHasChanged();
}

private void OnMessageDeleted(MessageDto message)
{
Logger.LogInformation("Message with ID {id} deleted", message.Id);

messages.Remove(message);
StateHasChanged();
}

private void OnMessageEdited(MessageDto oldMessage, MessageDto newMessage)
{
Logger.LogInformation("Message with ID {id} edited", oldMessage.Id);

messages[messages.IndexOf(oldMessage)] = newMessage;
StateHasChanged();
}

}
@inject MerpieClient Client
@inject MerpieHubConnection HubConnection
@inject ILogger<MessageList> Logger

<div class="flex flex-col-reverse gap-y-4">
@foreach (var message in messages)
{
<MessageDisplay Message="message"/>
}
</div>

@code {

private readonly List<MessageDto> messages = new();

protected override async Task OnInitializedAsync()
{
await HubConnection.StartConnection();

HubConnection.OnMessageSent += OnMessageSent;
HubConnection.OnMessageDeleted += OnMessageDeleted;
HubConnection.OnMessageEdited += OnMessageEdited;

// Fetch messages
if (await Client.GetMessages() is ApiResult<IEnumerable<MessageDto>>.Success success)
messages.AddRange(success.Value);
}

private void OnMessageSent(MessageDto message)
{
Logger.LogInformation("Message with ID {id} received", message.Id);

messages.Insert(0, message);
StateHasChanged();
}

private void OnMessageDeleted(MessageDto message)
{
Logger.LogInformation("Message with ID {id} deleted", message.Id);

messages.Remove(message);
StateHasChanged();
}

private void OnMessageEdited(MessageDto oldMessage, MessageDto newMessage)
{
Logger.LogInformation("Message with ID {id} edited", oldMessage.Id);

messages[messages.IndexOf(oldMessage)] = newMessage;
StateHasChanged();
}

}
This is a component in a Blazor WASM chat app I'm developing which job is to display a list of messages. However I'm wondering whether this is an alright-ish way to go about keeping a continually updating list of messages, because to me it feels a bit iffy. Especially the fact I have this Remove call which has to iterate through all the messages to remove it. I don't know how well this would scale or whether there is a better approach.
32 replies
CC#
Created by Thinker on 4/4/2023 in #help
✅ Is System.Half ever used?
Just wondering, what's the point of System.Half? It doesn't even have an alias unlike most of the other numeric types. I assume it's in the same boat as Int128 where it's a numeric type in System but doesn't have the runtime support of the other numeric types?
12 replies
CC#
Created by Thinker on 3/28/2023 in #help
✅ How to structure this login/signup page layout
10 replies
CC#
Created by Thinker on 3/19/2023 in #help
✅ Best practice when using HttpClient in a class
I have a class which essentially acts as a wrapper over an HttpClient as an abstraction for a web API. This class has a field private readonly HttpClient client; which is currently set through the constructor of the class, where I'm just kind of expecting the consuming code to have configured the base address and any other configuration in regards to the client itself. However, I don't know if this is considered good practice, or if there's some other way I'm not aware of. This class should also be usable with DI, so I don't know if I instead should have an IHttpClientFactory in the constructor or something instead.
116 replies
CC#
Created by Thinker on 3/13/2023 in #help
✅ Is it worth having an abstractions "layer" for a web API?
I'm working on a website project using an ASP.NET web API for the backend and Blazor WASM for the frontend. Since I'll one way or another need to call my web API from the Blazor project through an HttpClient, would it be worth abstracting this into its own project with classes which act as almost "front-ends" for the API itself with strongly typed methods corresponding to the API endpoints? Or would it just be more straightforward to just call the API through a raw HttpClient in the Blazor project?
7 replies
CC#
Created by Thinker on 3/11/2023 in #help
✅ Regex which matches strings containing things other than specific patterns
This is probably a very weird question (and also isn't strictly related to C#). I need a regex which matches strings which contain anything but a specific set of patterns. For instance, a string should match if it contains anything but substrings which match either <\d{5}> or \s+. I don't even know if this is possible, just wanna ask.
60 replies
CC#
Created by Thinker on 3/2/2023 in #help
✅ Lazily combine sets
I'm not expecting this to be possible but just asking in case. Is there any way to lazily combine sets, like if you did xs.Concat(ys) with regular enumerables? What I would be looking for is a way to take two IReadOnlySet<T>s and combine them in a way that you get back another IReadOnlySet<T> which is a combination of both of them, but which isn't evaluated immediately but rather lazily.
15 replies
CC#
Created by Thinker on 2/11/2023 in #help
✅ Error when including a project reference in a Blazor WASM project
I'm getting an error There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'browser-wasm'. only when including a ProjectReference to another project in my solution in a Blazor WASM project. Both projects are targeting net7.0. Do I have to do something special to get the project reference to work properly with WASM or something?
23 replies
CC#
Created by Thinker on 2/6/2023 in #help
❔ TargetFramework for targeting both Framework and Core
What's the TargetFramework you should use if you want interoperability with both Framework and Core? I think netstandard2.0 or netstandard2.1, right? This is for a project which has to target Framework 4.8.
44 replies